首页 > 其他 > 详细

JPA自定义模糊查询并将查询结果分页

时间:2019-11-11 13:26:13      阅读:152      评论:0      收藏:0      [点我收藏+]

dao层我尝试使用JPA自带的Like,但是不知道怎么进行分页,所以使用了@Query注解来完成

dao语句

@Query(value = "SELECT * from red_city_list where ztmc like %?1%",nativeQuery = true)
Page<CityRedListRecord> findByContentLike(String content, PageRequest pageRequest);
其中red_city_list表示查询的数据库名称,ztmc表示要查询的字段,CityRedListRecord表示实体类,content模糊查询字段
 //1.分页
 PageRequest pageRequest = PageRequest.of(cityRedListForm.getPageIndex(), cityRedListForm.getPageSize());
 //2.模糊查询查询并分页
 Page<CityRedListRecord> byZtmcLikePage = cityRedListRecordRepository.findByContentLike(cityRedListForm.getContent(), pageRequest);
byZtmcLikePage即为查询结果,可调用getContent()获取

JPA自定义模糊查询并将查询结果分页

原文:https://www.cnblogs.com/lxxcn/p/11834022.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!