************* 打开Mybatis-Plus的自动分页配置******************
@Configuration
public class MybatisPlusConfig {
@Bean
public PaginationInterceptor paginationInterceptor() {
PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
// 设置请求的页面大于最大页后操作, true调回到首页,false 继续请求 默认false
// paginationInterceptor.setOverflow(false);
// 设置最大单页限制数量,默认 500 条,-1 不受限制
// paginationInterceptor.setLimit(500);
// 开启 count 的 join 优化,只针对部分 left join
paginationInterceptor.setCountSqlParser(new JsqlParserCountOptimize(true));
return paginationInterceptor;
}
}
controller层****
@Autowired
private IStudentsService iStudentsService;
//查询所有
@RequestMapping("/uu")
@ResponseBody
public Object uu(Integer limit, Integer page,Students name){
//条件构造器
QueryWrapper queryWrapper= new QueryWrapper<>();
//动态模糊查询
if(name.getName()!=null){
queryWrapper.like(“name”,name.getName());
}else { }
//分页条件 page从第几页开始 limit每页个数
Page<Students> pages=new Page<Students>(page,limit);
// 自定义联表分页查询集合 包含总页数 总记录数 查询的集合等等
IPage<Students> aas= iStudentsService.selectStudentsrspage(pages,queryWrapper);
//调用查询的全部数据
List<Students> ss=aas.getRecords();
//int count= iComputersService.count();
//调用查询总记录数 和int count= iComputersService.count();一样
long counts= aas.getTotal();
Map<String, Object> result= new HashMap<String, Object>();
result.put("code", 0);
result.put("data", ss);
result.put("count", counts);
return result;
}
*********************mapper层 或者dao层 **********************
public interface StudentsMapper extends BaseMapper {
//自定义联表分页查询
IPage selectStudentsrspage(Page page,@Param(Constants.WRAPPER) Wrapper wrapper);
}
**service层
public interface IStudentsService extends IService {
//自定义联表分页查询
IPage selectStudentsrspage(Page page,@Param(Constants.WRAPPER) Wrapper wrapper);
}
serviceImpl层*****
@Service
public class StudentsServiceImpl extends ServiceImpl<StudentsMapper, Students> implements IStudentsService {
@Autowired
private StudentsMapper studentsMapper;
@Override
public IPage<Students> selectStudentsrspage(Page<Students> page, Wrapper<Students> wrapper) {
return studentsMapper.selectStudentsrspage(page,wrapper);
}
}
*************xxxx.xml层
<?xml version="1.0" encoding="UTF-8"?><select id="selectStudentsrspage" resultType="com.ysd.rsst.entity.Students">
SELECT * FROM students a JOIN memberships b on a.membershipid=b.mid ${ew.customSqlSegment}
</select>