在众多ORM持久层框架中,凯哥还是比较喜欢使用mybatis。至于mybatis的好处在此就不一一列举了。本篇主要介绍的是在spring boot中怎么整合mybatis及git的分页插件。
工具/原料
方法/步骤
1整合步骤: 1:pom.xml中添加jar支持 2:配置数据源 3:编写代码测试
2一:pom.xml文件中添加jar支持 1.1 parent org.springframework.boot spring-boot-starter-parent 2.0.3.RELEASE
31.2 设置编码utf-8 UTF-8 UTF-8 1.8
41.3 添加依赖 org.springframework.boot spring-boot-starter-web org.mybatis.spring.boot mybatis-spring-boot-starter 1.3.2 mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-test test org.apache.commons commons-lang3 3.4 com.fasterxml.jackson.core jackson-core com.fasterxml.jackson.core jackson-databind com.fasterxml.jackson.datatype jackson-datatype-joda com.fasterxml.jackson.module jackson-module-parameter-names com.github.pagehelper pagehelper-spring-boot-starter 1.2.5 com.alibaba druid-spring-boot-starter 1.1.9 org.apache.tomcat.embed tomcat-embed-jasper javax.servlet jstl
51.4 添加插件 org.springframework.boot spring-boot-maven-plugin
二:配置数据源
22.2:配置加载mapper位置及扫描pojo包:
三:编码测试
13.1:创建测试数据库 CREATE TABLE `t_user` ( `userId` int(11) NOT NULL AUTO_INCREMENT, `userName` varchar(255) NOT NULL, `password` varchar(255) NOT NULL, `phone` varchar(255) NOT NULL, PRIMARY KEY (`userId`) ) ENGINE=InnoDB AUTO_INCREMENT=1001 DEFAULT CHARSET=utf8;
4 使用postman 进行测试