spring boot mybatiscodehelper外掛和pagehelper外掛
阿新 • • 發佈:2018-12-27
1.idea搜尋外掛MybatisCodeHelper下載
需要啟用碼https://github.com/gejun123456/MyBatisCodeHelper-Pro
2.右下角外掛新增表,選擇mapperAnnotation,lombok,Serializable
3.新增方法,直接寫方法名,然後全選,右鍵,generate mybatis xml,自動生成xml方法
具體方法看https://gejun123456.github.io/MyBatisCodeHelper-Pro/#/methodNameToSql
4.pagehelper外掛引入
<dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.10</version> </dependency>
5.使用,三個引數分別是第幾頁,每頁幾條資料和排序規則
public List<User> bbb(Integer minId,Integer maxId){
PageHelper.startPage(2,5,"Id asc,Name desc");
List<User> list = userMapper.findByIdGreaterThanEqualAndIdLessThanEqual(minId,maxId);
return list;
}
6.在控制檯顯示sql語句,application.properties裡寫,com.mapper是你mapper介面所在的位置
mybatis.mapper-locations=classpath:/mapperxml/*Mapper.xml
mybatis.type-aliases-package=com.mapper
logging.level.com.mapper=debug