Mybatis Plus自帶分頁和PageHelper有什么區(qū)別?
網(wǎng)上描述:
Mapper Plus自帶分頁P(yáng)aginationInterceptor對象,雖然說目前沒有什么問題,并且使用簡單,但是個人感覺有個弊端:目前個人使用中,想要用Mapper Plus自帶的分頁功能的話需要在mapper對象中傳入一個Page對象才可以實(shí)現(xiàn)分頁,這樣耦合度是不是太高了一點(diǎn),從web到service到mapper,這個Page對象一直都在傳入,這樣的使用讓人感覺有點(diǎn)麻煩~
Mybatis Plus整合PageHelper分頁
Mybatis Plus整合PageHelper分頁
參考URL: https://blog.csdn.net/m0_37701381/article/details/100719280
SpringBoot2.1+MybatisPlus+Pagehelper框架整合(其中與Dubbo整合時(shí)分頁失效的疑問與解決)
參考UIRL: https://blog.csdn.net/lstcui/article/details/89068918
springboot自定義攔截器獲取分頁參數(shù)
ThreadLocal Pager 分頁的一種解決方案
參考URL: https://blog.csdn.net/cmdsmith/article/details/66969728
spring boot下配置mybatis-plus分頁插件
springBoot 使用 mybatis-plus 插件 實(shí)現(xiàn)分頁
https://blog.csdn.net/sinat_34338162/article/details/83543994?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
需要寫一個分頁的配置類分頁功能才能生效
/**
* //Spring boot方式
* @Description: MybatisPlus配置類
*/
@Configuration
public class MyBatisPlusConfig {
/**
* 分頁插件
* @return
*/
@Bean
public PaginationInterceptor paginationInterceptor() {
return new PaginationInterceptor();
}
}
單表分頁查詢
如果只是單表,那么分頁查詢就容易的多了。
這里的@ModelAttribute注解可以將前端傳過來的current和size字段映射到Page對象中。
/**
* @param page 查詢一般傳入?yún)?shù)為current和size, 例如/listPage?current=1&size=5,
* @return 返回分頁數(shù)據(jù)
*/
@RequestMapping(value = "/page", method = RequestMethod.GET)
public ResponseObj<Page<T>> listPage(@ModelAttribute Page<T> page, @ModelAttribute T model) {
Page<T> pageList = service.selectPage(page, new EntityWrapper<>(model));
for (T eachObj : pageList.getRecords()) {
queryFilter(eachObj);
}
return new ResponseObj<>(pageList, RetCode.SUCCESS);
}
@RestController
@RequestMapping("/student")
public class StudentController {
@Autowired
IStudentService studentService;
@RequestMapping(value = "/findAll",method = RequestMethod.POST)
public Object findAll(HttpServletRequest request){
//獲取前臺發(fā)送過來的數(shù)據(jù)
Integer pageNo = Integer.valueOf(request.getParameter("pageNo"));
Integer pageSize = Integer.valueOf(request.getParameter("pageSize"));
IPage<Student> page = new Page<>(pageNo, pageSize);
QueryWrapper<Student> wrapper = new QueryWrapper<>();
Student student = new Student();
student.setId(1);
wrapper.setEntity(student);
return studentService.page(page,wrapper);
}
}
總結(jié): 整體思路很簡單,需要2個參數(shù),一個是 IPage page實(shí)例,傳入pageNo、pageSize ,一個是QueryWrapper wrapper實(shí)例。 使用時(shí)把page傳入會自動在sql語句后面添加limit。
自定義sql分頁查詢
有時(shí)候查詢的數(shù)據(jù)難免會出現(xiàn)多表連接查詢,或者是一些復(fù)雜的sql語句,但是這些語句也是需要支持分頁查詢的。
先定義查詢接口,第一個參數(shù)要是分頁的參數(shù)。
步驟一:在mapper文件中,編寫對應(yīng)的分頁查詢接口。
步驟二:在xml中編寫對應(yīng)的sql語句,小編這里演示的 “${ew.customSqlSegment}”,這個是如果你想自定義的sql語句,也想使用wrapper查詢條件構(gòu)造器,則需要在mapper接口中添加參數(shù),以及xml中也要有固定。
PageHelper
PageHelper用于查詢語句分頁,讓分頁更簡單、代碼更優(yōu)雅。文章來源:http://www.zghlxwxcb.cn/news/detail-835078.html
參考
MyBatis-Plus 分頁查詢以及自定義sql分頁
參考URL: https://blog.csdn.net/weixin_38111957/article/details/91554108?depth_1-utm_source=distribute.pc_relevant.none-task&utm_source=distribute.pc_relevant.none-task
mybatis-plus分頁查詢
參考URL: https://www.jianshu.com/p/43bfe6fe8d89文章來源地址http://www.zghlxwxcb.cn/news/detail-835078.html
到了這里,關(guān)于spring boot Mybatis Plus分頁的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!