# Spring Boot 集成 MyBatis, 分页插件 PageHelper, 通用 Mapper
- [Spring Boot 1.5.1.RELEASE](https://github.com/spring-projects/spring-boot)
- [mybatis-spring-boot-starter](https://github.com/mybatis/spring-boot-starter)
- [mapper-spring-boot-starter](https://github.com/abel533/mapper-boot-starter)
- [pagehelper-spring-boot-starter](https://github.com/pagehelper/pagehelper-spring-boot)
## 新书《MyBatis 从入门到精通》
![MyBatis 从入门到精通](https://github.com/mybatis-book/book/raw/master/book.png)
预售地址:[京东](https://item.jd.com/12103309.html),[当当](http://product.dangdang.com/25098208.html),[亚马逊](https://www.amazon.cn/MyBatis从入门到精通-刘增辉/dp/B072RC11DM/ref=sr_1_18?ie=UTF8&qid=1498007125&sr=8-18&keywords=mybatis)
CSDN博客:http://blog.csdn.net/isea533/article/details/73555400
GitHub项目:https://github.com/mybatis-book/book
## 项目依赖
```xml
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<!--mapper-->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>1.1.4</version>
</dependency>
<!--pagehelper-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.1</version>
</dependency>
```
## Spring DevTools 配置
感谢[emf1002](https://github.com/emf1002)提供的解决方案。
在使用 DevTools 时,通用Mapper经常会出现 class x.x.A cannot be cast to x.x.A。
同一个类如果使用了不同的类加载器,就会产生这样的错误,所以解决方案就是让通用Mapper和实体类使用相同的类加载器即可。
DevTools 默认会对 IDE 中引入的所有项目使用 restart 类加载器,对于引入的 jar 包使用 base 类加载器,因此只要保证通用Mapper的jar包使用 restart
类加载器即可。
在 `src/main/resources` 中创建 META-INF 目录,在此目录下添加 spring-devtools.properties 配置,内容如下:
```properties
restart.include.mapper=/mapper-[\\w-\\.]+jar
restart.include.pagehelper=/pagehelper-[\\w-\\.]+jar
```
使用这个配置后,就会使用 restart 类加载加载 include 进去的 jar 包。
## 集成 MyBatis Generator
通过 Maven 插件集成的,所以运行插件使用下面的命令:
>mvn mybatis-generator:generate
Mybatis Geneator 详解:
>http://blog.csdn.net/isea533/article/details/42102297
## application.properties 配置
```properties
#mybatis
mybatis.type-aliases-package=tk.mybatis.springboot.model
mybatis.mapper-locations=classpath:mapper/*.xml
#mapper
#mappers 多个接口时逗号隔开
mapper.mappers=tk.mybatis.springboot.util.MyMapper
mapper.not-empty=false
mapper.identity=MYSQL
#pagehelper
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql
```
## application.yml 配置
完整配置可以参考 [src/main/resources/application-old.yml](https://github.com/abel533/MyBatis-Spring-Boot/blob/master/src/main/resources/application-old.yml) ,和 MyBatis 相关的部分配置如下:
```yaml
mybatis:
type-aliases-package: tk.mybatis.springboot.model
mapper-locations: classpath:mapper/*.xml
mapper:
mappers:
- tk.mybatis.springboot.util.MyMapper
not-empty: false
identity: MYSQL
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
```
注意 mapper 配置,因为参数名固定,所以接收参数使用的对象,按照 Spring Boot 配置规则,大写字母都变了带横线的小写字母。针对如 IDENTITY(对应i-d-e-n-t-i-t-y)提供了全小写的 identity 配置,如果 IDE 能自动提示,看自动提示即可。
## SSM集成的基础项目
>https://github.com/abel533/Mybatis-Spring
## MyBatis工具 http://www.mybatis.tk
- 推荐使用 Mybatis 通用 Mapper3 https://github.com/abel533/Mapper
- 推荐使用 Mybatis 分页插件 PageHelper https://github.com/pagehelper/Mybatis-PageHelper
## 作者信息
- 作者博客:http://blog.csdn.net/isea533
- 作者邮箱:abel533@gmail.com
- 如需加群,请通过 http://mybatis.tk 首页按钮加群。
没有合适的资源?快使用搜索试试~ 我知道了~
springboot集成mybatis分页,freemark,spring,logback完整小例子
共110个文件
java:20个
class:20个
xml:11个
5星 · 超过95%的资源 需积分: 10 44 下载量 164 浏览量
2017-11-17
11:42:32
上传
评论 2
收藏 25.15MB ZIP 举报
温馨提示
springboot集成mybatis分页,freemark,spring,logback完整小例子, 可直接运行
资源推荐
资源详情
资源评论
收起资源包目录
springboot集成mybatis分页,freemark,spring,logback完整小例子 (110个子文件)
3171ebe9c5a79917f9ae6c5e0f76a86ab2dace 2KB
UserInfoController.class 4KB
CountryController.class 3KB
MyBatis331Test.class 3KB
CityController.class 3KB
CountryService.class 3KB
UserInfoService.class 2KB
CityService.class 2KB
UserInfo.class 2KB
CountryServiceTest.class 2KB
Application.class 2KB
City2.class 2KB
BaseEntity.class 1KB
MyBatis331Mapper.class 1KB
WebMvcConfig.class 1KB
Country.class 798B
City.class 750B
UserInfoMapper.class 587B
MyMapper.class 351B
CountryMapper.class 296B
CityMapper.class 287B
config 309B
style.css 2KB
style.css 2KB
description 73B
exclude 240B
index.ftl 7KB
index.ftl 7KB
view.ftl 1KB
view.ftl 1KB
.gitignore 138B
HEAD 185B
HEAD 185B
HEAD 32B
HEAD 23B
pack-c014439f8fc57c1c8408e0b1431691f14518abf8.idx 12KB
mybatis-spring-boot.iml 10KB
index 5KB
mybatis-spring-boot-1.0.0-SNAPSHOT.jar 27.71MB
CountryController.java 4KB
UserInfoController.java 3KB
MyBatis331Test.java 3KB
CityController.java 3KB
CountryService.java 3KB
MyBatis331Mapper.java 3KB
UserInfo.java 3KB
UserInfoService.java 2KB
City2.java 2KB
CityService.java 2KB
Country.java 2KB
BaseEntity.java 2KB
WebMvcConfig.java 2KB
City.java 2KB
UserInfoMapper.java 2KB
MyMapper.java 2KB
CityMapper.java 1KB
CountryMapper.java 1KB
Application.java 1KB
CountryServiceTest.java 980B
jquery-1.11.1.min.js 146KB
jquery-1.11.1.min.js 146KB
inputFiles.lst 2KB
createdFiles.lst 762B
inputFiles.lst 474B
createdFiles.lst 194B
master 185B
master 41B
README.md 4KB
mybatis-spring-boot-1.0.0-SNAPSHOT.jar.original 67KB
pack-c014439f8fc57c1c8408e0b1431691f14518abf8.pack 141KB
packed-refs 107B
application.properties 692B
application.properties 692B
application-dev.properties 501B
application-dev.properties 501B
application-production.properties 432B
application-production.properties 432B
pom.properties 135B
spring-devtools.properties 98B
spring-devtools.properties 98B
pre-rebase.sample 5KB
update.sample 4KB
pre-commit.sample 2KB
pre-push.sample 1KB
prepare-commit-msg.sample 1KB
commit-msg.sample 896B
pre-receive.sample 544B
applypatch-msg.sample 478B
pre-applypatch.sample 424B
post-update.sample 189B
test.sql 11KB
test.sql 11KB
city.sql 613B
banner.txt 1KB
banner.txt 1KB
tk.mybatis.springboot.test.CountryServiceTest.txt 343B
tk.mybatis.springboot.mapper.MyBatis331Test.txt 341B
logback.xml 6KB
logback.xml 6KB
TEST-tk.mybatis.springboot.mapper.MyBatis331Test.xml 6KB
共 110 条
- 1
- 2
资源评论
- 爱听相声的挨踢人士2018-02-26还行,可以看看的。阿萨
土豆_123
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功