使用idea实现springboot Mybatis 整合(springboot 2.x)
写在前面本来这篇博文老在就写好了,但是后来发现很多功能其实根本就没有检验通过就发出来了,导致遗留了很多坑,比如最难搞的就是SqlSessionFactory和PageHelper,之前写过关于springboot1.5.6版本的整合,这段时间刚好springboot发布了2.0的正式版本,很多同学可能没有注意版本,导致了整合的时候出现了很多很多的问题,这几天刚好有空就试着整合一下springboo
写在前面
本来这篇博文老在就写好了,但是后来发现很多功能其实根本就没有检验通过就发出来了,导致遗留了很多坑,比如最难搞的就是SqlSessionFactory和PageHelper,之前写过关于springboot1.5.6版本的整合,这段时间刚好springboot发布了2.0的正式版本,很多同学可能没有注意版本,导致了整合的时候出现了很多很多的问题,这几天刚好有空就试着整合一下springboot2.0 mybatis,发现了很多很多的坑,而且网上的资源也不多,终于在两天的踩坑中成功整合了,并且将翻页功能修复好了,废话不多说了,看代码:
环境/版本一览:
开发工具:Intellij IDEA 2017.1.3
springboot: 2.0.1.RELEASE
jdk:1.8.0_40
maven:3.3.9
alibaba Druid 数据库连接池:1.1.9
额外功能:
PageHelper 分页插件
mybatis generator 自动生成代码插件(本次搭建就不讲解了,请参照Spring boot Mybatis 整合(完整版))
开始搭建:
创建项目:


添加基础的依赖: 
依赖文件:
按照pom文件补齐需要的依赖:
<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.winterchen</groupId> <artifactId>springboot2-mybatis-demo</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>springboot2-mybatis-demo</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.4</version> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-core</artifactId> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> </dependency> <dependency> <groupId>com.fasterxml
原创不易,完成人机校验,阅读全文
相关推荐
学习笔录-SPRING BOOT使用idea快速实现spring boot(1.5*版本) 与mybatis的整合工作小总结spring boot 2.x 整合mybaits及分页插件学习笔录-SPRING BOOTSpringBoot 整合 Redis 的简单案例GIT项目SpringBoot-MyBatis Spring boot + MyBatis 提供 SaaS 接口服务工作小总结spring boot 和mybatis整合打印sql语句工作小总结mybatis整合spring boot错误:.getTimeout()Ljava/lang/Integer;GIT项目spring boot整合mybatis+durid+事务+PageHelper分页插件+sql打印的整合经验分享spring boot 整合mybatis 提示Invalid bound statement 解决记录