mybatis 手写分页
mybatis 手动分页查询 .xml文件
SELECT
....
FROM dip_pack_box AS t1
LEFT JOIN dip_pack_content AS t2 ON t1.id = t2.superior_id AND t2.delete_flag = 0
<where>
t1.delete_flag = 0
<if test= "null != name and '' != name">
<bind name="pattern_name" value="'%' + name +'%'"/>
AND t1.name like #{pattern_name}
</if>
</where>
LIMIT #{index}, #{pageSize}
</select>
java文件
@Override
public PageUtil pageSearch(Map<String,Object> param) {
//第几页
Integer current = (Integer) param.get("pageIndex");
//每页大小
Integer pageSize = (Integer) param.get("pageSize");
int index = (current - 1) * pageSize;
param.put("index",index);
List<DipPackBoxEntity> boxEntityList = dipPackBoxDao.pageSearch(param);
IPage<DipPackBoxEntity> iPage = new Page<>();
iPage.setRecords(boxEntityList);
return new PageUtil(iPage);
}
扩展性更好使用了<bind name = "起个别名 比如pattern_name " value = " 指定产来的参数 比如 name "> 元素