Mybatis-Plus(MP)自定义联表分页

************* 打开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>
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值