首先需要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. 关于.net core 在docker中监听地址设置踩坑记

    1.今天在做docker容器的时候发现如果将.net core 内部监听地址设置为localhost:8888. 2.在docker build -p 6444:8888 运行容器后,外部通过6444 ...

  2. vue-quill-editor-upload : 实现vue-quill-editor上传图片到服务器

    vue-quill-editor-upload git: https://github.com/NextBoy/vu... A plug-in for uploading images to your ...

  3. 让div垂直居中

    参考链接:https://www.cnblogs.com/softwarefang/p/6095806.html 以前我的方法总是比较粗暴,纯粹通过margin来实现,这个方法的缺点不仅在于需要多次微 ...

  4. 魔兽争霸RPG游戏-军团战争-游戏经验总结

    终于要写这篇了,上一篇是个意外. 2015年关注,一代鬼王Xun和GGL比赛.晚上11点之后,经常有水友赛.主播xun,会带着一帮小弟,玩一些游戏.比如魔兽争霸6v6,2v2,RPG游戏-军团战争,疯 ...

  5. vjudge A - Beautiful numbers

    A - Beautiful numbers Volodya is an odd boy and his taste is strange as well. It seems to him that a ...

  6. E-UTRA channel bandwidths per operating band (36.101)

    E-UTRA channel bandwidths per operating band (36.101) watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/ ...

  7. 空暇时候思考之const

    对于多数人来说那些const的使用方法比方修饰返回值和修饰參数都应该是十分好理解的下来我要讨论 对于C语言中 #include <stdio.h> void main() { const ...

  8. 在Linux的终端中显示BMPString的内容

    在上一篇博文中,介绍了怎样在 Windows 的控制台界面下输出 BMPString 的内容,可是那里的方法在 Linux 下不适用.假设将那里的演示样例代码放到 Linux 下运行.输出的结果为乱码 ...

  9. zzulioj--1828-- 贪心的小猫咪(贪心模拟)

    1828: 贪心的小猫咪 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 14  Solved: 4 SubmitStatusWeb Board Des ...

  10. Gcc/MinGW/Cygwin/Msys 分别是什么?

    一.GCC的历史 GCC是一个原本用于Unix-like系统下编程的编译器. 不过,现在GCC也有了许多Win32下的移植版本. 所以,也许对于许多Windows开发者来说,GCC还是一个比较陌生的东 ...