首先需要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的更多相关文章

  1. springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+freemarker+layui

    前言: 开发环境:IDEA+jdk1.8+windows10 目标:使用springboot整合druid数据源+mysql+mybatis+通用mapper插件+pagehelper插件+mybat ...

  2. Springboot集成mybatis通用Mapper与分页插件PageHelper

    插件介绍 通用 Mapper 是一个可以实现任意 MyBatis 通用方法的框架,项目提供了常规的增删改查操作以及 Example 相关的单表操作.通用 Mapper 是为了解决 MyBatis 使用 ...

  3. springboot整合mybatis通用Mapper

    参考: https://blog.csdn.net/x18707731829/article/details/82814095 https://www.jianshu.com/p/6d2103451d ...

  4. springboot学习笔记:9.springboot+mybatis+通用mapper+多数据源

    本文承接上一篇文章:springboot学习笔记:8. springboot+druid+mysql+mybatis+通用mapper+pagehelper+mybatis-generator+fre ...

  5. SpringBoot 3.SpringBoot 整合 MyBatis 逆向工程以及 MyBatis 通用 Mapper

    一.添加所需依赖,当前完整的pom文件如下: <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi=&qu ...

  6. (一 、上)搭建简单的SpringBoot + java + maven + mysql + Mybatis+通用Mapper 《附项目源码》

    最近公司一直使用 springBoot 作为后端项目框架, 也负责搭建了几个新项目的后端框架.在使用了一段时间springBoot 后,感觉写代码 比spring 更加简洁了(是非常简洁),整合工具也 ...

  7. springboot学习笔记:11.springboot+shiro+mysql+mybatis(通用mapper)+freemarker+ztree+layui实现通用的java后台管理系统(权限管理+用户管理+菜单管理)

    一.前言 经过前10篇文章,我们已经可以快速搭建一个springboot的web项目: 今天,我们在上一节基础上继续集成shiro框架,实现一个可以通用的后台管理系统:包括用户管理,角色管理,菜单管理 ...

  8. Spring boot集成 MyBatis 通用Mapper

    配置 POM文件 <parent> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  9. spring boot集成MyBatis 通用Mapper 使用总结

    spring boot集成MyBatis 通用Mapper 使用总结 2019年 参考资料: Spring boot集成 MyBatis 通用Mapper SpringBoot框架之通用mapper插 ...

随机推荐

  1. 紫书 习题8-11 UVa 1615 (区间选点问题)

    这个点就是贪心策略中的区间选点问题. 把右端点从大到小排序, 左端点从小到大排序. 每次取区间右端点就可以了, 到不能覆盖的时候就ans++, 重新取点 ps:这道题不考虑精度也可以过 要着重复习一下 ...

  2. Myeclipse学习总结(7)——Eclipse插件之Maven配置及问题解析

    前言: 今天在自己环境装了Maven环境, 并且安装了Eclipse插件, 在查找插件过程中确实遇到一些问题, 好不容易找到一个  却又有问题. 装好了插件之后, 用Eclipse创建Maven项目却 ...

  3. ActiveMQ学习总结(9)——Linux中安装ActiveMQ

    1.新建一个文件夹activeMQ   mkdir /server 2.授权    chmod 777 /server 3.下载activeMQ安装包,拷贝到/activeMQ目录下 apache-a ...

  4. NYIST 1019 G.亲戚来了

    G.亲戚来了 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 Bob 一家人要去下馆子,为什么呢?因为他姑姑的大爷的叔叔的孙子的表叔的婶婶的儿子来了,亲戚来了当然要下 ...

  5. 严重: 文档无效: 找不到语法。 at (null:2:19)

    1.错误描写叙述 严重: 文档无效: 找不到语法. at (null:2:19) org.xml.sax.SAXParseException; systemId: file:/D:/MyEclipse ...

  6. 《鸟哥的Linux私房菜-基础学习篇(第三版)》(三)

    第2章 Linxu怎样学习         1. Linux当前的应用角色 当前的Linux常见的应用可略分为企业应用和个人应用双方面. 首先谈了企业环境的利用. 1)网络server. 2)关键任务 ...

  7. 我的modelsim常用DO文件设置

    在modelsim中使用do文件是非常方便的进行仿真的一种方法,原来接触到的一些项目不是很大,用modelsim仿真只需要仿真单独的一些模块,最近接触的项目比较大,是几个人分开做的,所以前后模块的联合 ...

  8. android常用控件的使用方法

    引言 xml很强大 TextView <TextView android:id="@+id/text_view" android:layout_width="mat ...

  9. js中Json字符串如何转成Json对象(4种转换方式)

    js中Json字符串如何转成Json对象(4种转换方式) 一.总结 一句话总结:原生方法(就是浏览器默认支持的方法) 浏览器支持的转换方式(Firefox,chrome,opera,safari,ie ...

  10. Persistence

    Most of the programs we have seen so far are transient in the sense that they run for a short time a ...