mybatis-plus自定义sql分页查询
1、TsparamServiceImpl Service里面查询方法
调用baseMapper.selectMyPage2(page, qw);
qw是 QueryWrapper 查询条件
@Override
    public PageUtils queryPageByPID(Map<String, Object> params) {
        Integer pageIndex = Integer.parseInt((String) params.get("page")); //第几页
        Integer limit = Integer.parseInt((String) params.get("limit"));//每页数
        QueryWrapper<TsparamEntity> qw = new QueryWrapper<>();
        String paramtypeid = (String) params.get("paramtypeid");
        if(StringUtils.hasText(paramtypeid)){
            qw.eq("t1.paramtypeid",paramtypeid);
        }
        String key= (String) params.get("key");
        if(StringUtils.hasText(key)){
            qw.and(w->{
                w.eq("t1.pid",key).or().like("t1.pname",key);
            });
        } 
        Page<TsparamEntity> page = new Page<>(pageIndex,limit);
        IPage<TsparamEntity> mapIPage = this.baseMapper.selectMyPage2(page, qw);
        return new PageUtils(mapIPage);
    }2、TsparamDao 添加接口方法 selectMyPage2
@Mapper
public interface TsparamDao extends BaseMapper<TsparamEntity> {
    /**
     * 自定义sql分页
     * @param page
     * @param queryWrapper 看这里看这里,如果自定义的方法中需要用到wrapper查询条件,需要这样写
     * @return
     */
    //IPage<TsparamEntity> selectMyPage(IPage<TsparamEntity> page, @Param(Constants.WRAPPER) Wrapper<TsparamEntity> queryWrapper);
    IPage<TsparamEntity> selectMyPage2(IPage<TsparamEntity> page,@Param(Constants.WRAPPER) Wrapper<TsparamEntity> queryWrapper);
}3、mapper.xml
    <select id="selectMyPage2" resultType="com.rdhl.modules.lis.entity.TsparamEntity">
         select t1.*,t2.valuename from tsparam t1
         left join tsparamvalue t2 on t1.pid=t2.pid and t1.pvalue=t2.valueid
         ${ew.customSqlSegment}
    </select>
${ew.customSqlSegment}  会自动根据qw 和param参数生成where 语句 
在qw条件中,我们可以直接使用 表别名.字段名 进行where条件的拼装 如: qw.eq("t1.paramtypeid",paramtypeid);