使用RowBounds实现分页,
举例:第一页10条数据:startLine = 0,endLine = 10;
param.getPage():第几页
param.getLimit():多少条
说明: new RowBounds(0, 10),即第一页,每页取10条数据
List<ListDto> selectMyPage(RowBounds rowBounds, @Param("ew") QueryWrapper<ListDto> wrapper);
int startLine = (param.getPage()-1)*param.getLimit();
int endLine = param.getPage()*param.getLimit();
List<ListDto> list = this.baseMapper.selectMyPage(new RowBounds(startLine,endLine),this.initQueryWrapper(param));
private QueryWrapper<ListDto> initQueryWrapper(ListDto param){
QueryWrapper<ListDto> queryWrapper = new QueryWrapper<>();
if(param!=null){
String Code = param.getCode();
queryWrapper
.eq(StringUtils.isNotBlank(Code),"t1.code",Code);
}
return queryWrapper;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="ListDao">
<select id="selectMyPage" resultType="ListDto">
SELECT * FROM t
LEFT JOIN t1 ON t.plan_hosp_id = t1.plan_hosp_id
left join t2 on t1.control_id = t2.control_id
<where>
${ew.sqlSegment}
</where>
</select>
</mapper>
mybatisPlus拼接查询条件