springboot 使用mybatis 通用Mapper,pagehelper
首先需要maven导入需要的包,这里用的是sqlserver,druid,jtds连接数据库
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.27</version>
</dependency>
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
<!--mapper-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>
<!--pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency>
然后在application.properties中配置使用
# 驱动配置信息
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
spring.datasource.url = jdbc:jtds:sqlserver://路径/库
spring.datasource.username = **
spring.datasource.password = **
spring.datasource.driverClassName = net.sourceforge.jtds.jdbc.Driver #mybatis
mybatis.typeAliasesPackage=com.example.bean
mybatis.mapperLocations=classpath*:/mybatis/mapper/*Mapper.xml
mybatis.configuration.use-generated-keys=true
mybatis.configuration.mapUnderscoreToCamelCase=true #分页插件
pagehelper.helperDialect=sqlserver
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
其中:
com.example.bean:放置数据库实体类
mybatis/mapper:mybatis的mapper.xml(自定义方法配置)

接口类自定义基类IBaseMapper(注意:不要跟其他mapper类放在一起)
/**
* 通用 Mapper接口
*
* @author sky
* @version 1.0
*/ public interface IBaseMapper<T extends AbstractDBEntity> extends Mapper<T>, MySqlMapper<T> { }
在入口类加上(其中com.example.mapper为mapper类放置包名)
@MapperScan(basePackages = { "com.example.mapper" })
这样就可以使用mybatis了
配置通用mapper
网上的方法在配置中使用mapper.mappers等等不知道为什么不行,在这里使用@Configuration的方式,注意入口类添加@ComponentScan扫描
新建MapperConfig类
/**
* @author sky
* @version 1.0
*/
@Configuration
public class MapperConfig { @Bean
public MapperScannerConfigurer mapperScannerConfigurer() {
MapperScannerConfigurer mapperScannerConfigurer = new MapperScannerConfigurer();
mapperScannerConfigurer.setBasePackage("com.example.mapper");
Properties propertiesMapper = new Properties();
//通用mapper位置,不要和其他mapper、dao放在同一个目录
propertiesMapper.setProperty("mappers", IBaseMapper.class.getName());
propertiesMapper.setProperty("notEmpty", "false");
mapperScannerConfigurer.setProperties(
propertiesMapper);
return mapperScannerConfigurer;
} }
测试新建mapper实现:()
/**
* @author sky
* @version 1.0
*/
public interface RegionMapper extends IBaseMapper<Region> {
}
这里就不做多实现了。。
springboot 使用mybatis 通用Mapper,pagehelper的更多相关文章
- springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+freemarker+layui
前言: 开发环境:IDEA+jdk1.8+windows10 目标:使用springboot整合druid数据源+mysql+mybatis+通用mapper插件+pagehelper插件+mybat ...
- Springboot集成mybatis通用Mapper与分页插件PageHelper
插件介绍 通用 Mapper 是一个可以实现任意 MyBatis 通用方法的框架,项目提供了常规的增删改查操作以及 Example 相关的单表操作.通用 Mapper 是为了解决 MyBatis 使用 ...
- springboot整合mybatis通用Mapper
参考: https://blog.csdn.net/x18707731829/article/details/82814095 https://www.jianshu.com/p/6d2103451d ...
- springboot学习笔记:9.springboot+mybatis+通用mapper+多数据源
本文承接上一篇文章:springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+fre ...
- SpringBoot 3.SpringBoot 整合 MyBatis 逆向工程以及 MyBatis 通用 Mapper
一.添加所需依赖,当前完整的pom文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...
- (一 、上)搭建简单的SpringBoot + java + maven + mysql + Mybatis+通用Mapper 《附项目源码》
最近公司一直使用 springBoot 作为后端项目框架, 也负责搭建了几个新项目的后端框架.在使用了一段时间springBoot 后,感觉写代码 比spring 更加简洁了(是非常简洁),整合工具也 ...
- springboot学习笔记:11.springboot+shiro+mysql+mybatis(通用mapper)+freemarker+ztree+layui实现通用的java后台管理系统(权限管理+用户管理+菜单管理)
一.前言 经过前10篇文章,我们已经可以快速搭建一个springboot的web项目: 今天,我们在上一节基础上继续集成shiro框架,实现一个可以通用的后台管理系统:包括用户管理,角色管理,菜单管理 ...
- Spring boot集成 MyBatis 通用Mapper
配置 POM文件 <parent> <groupId>org.springframework.boot</groupId> <artifactId>sp ...
- spring boot集成MyBatis 通用Mapper 使用总结
spring boot集成MyBatis 通用Mapper 使用总结 2019年 参考资料: Spring boot集成 MyBatis 通用Mapper SpringBoot框架之通用mapper插 ...
随机推荐
- 'Upgrade' header is missing
spring-websocket 握手失败是因为 有拦截器 注释掉拦截器就OK
- 开源 PHP 项目找队友、顾问、指导、贡献者等等
介绍站点还没做,先直接甩代码链接了 https://github.com/litphp/litphp Lit是什么? Lit是我一直在撸的个人框架,按第一次上传代码来说历史 超过4年 了,从还能支持P ...
- codevs1281 矩阵乘法 快速幂 !!!手写乘法取模!!! 练习struct的构造函数和成员函数
对于这道题目以及我的快速幂以及我的一节半晚自习我表示无力吐槽,, 首先矩阵乘法和快速幂没必要太多说吧,,嗯没必要,,我相信没必要,,实在做不出来写两个矩阵手推一下也就能理解矩阵的顺序了,要格外注意一些 ...
- Qt之图形(QPainter的基本绘图)
简述 Qt中提供了强大的2D绘图系统,可以使用相同的API在屏幕和绘图设备上进行绘制,它主要基于QPainter.QPaintDevice和QPaintEngine这三个类. QPainter用来执行 ...
- [React Native] Dismiss the Keyboard in React Native
In this lesson you will learn how create a re-usable component that gives the user the ability to di ...
- 转:iPhone libxml2 not found during build
在新建的一个项目中,出现编译错误,发现是缺少了libxml2.dylib,后面将这个资源包添加了,编译还是出现标题上所说的问题 #import <libxml/tree.h> //#imp ...
- sage开发url替换字符串
/// <summary> /// Url字段值替换,无该字段则加入 /// </summary> /// <param ...
- 数位$dp$
数位\(dp\)搞了一上午才搞懂.靠这种傻\(X\)的东西竟然花了我一上午的时间. 数位\(dp\) 概念 数位\(dp\)就是强制你分类一些数,例如给你一段区间,然后让你求出不包含\(2\)的数的个 ...
- 我的Spring MVC第一个应用 (最终版)
项目结构图: 代码如下: Product package com.mstf.bean; import java.io.Serializable; /** * Product类,封装了一些信息,包含三个 ...
- RelativeLayout中的baseline
比如,加入两个相邻的TextView,给第二个TextView一个大一点的padding(比如20dp),如果加了layout_alignBaseline到第二个TextView中的话, TextVi ...