获取登录用户
- 通过 LoginUserBO.getLoginUser(); 方法即可获取当前登录用户
分页和排序
- 框架分页使用PageHelper 具体用法可以参考官方文档: PageHelper官方文档
- 分页加排序实现方式: 在要分页的sql、前面加
- pageNum 当前页码
- pageSize 每页显示多少条
- orderBy 排序规则 固定写法postListParamPO.getOrderBy(PostPO.class)
public List<PostPO> queryPageList(PostListParamPO postListParamPO) {
LoginUserBO loginUserBO = LoginUserBO.getLoginUser()
//搜索条件
LambdaQueryWrapper<PostPO> queryWrapper = Wrappers.lambdaQuery(PostPO.class)
.like(KPStringUtil.isNotEmpty(postListParamPO.getPostCode()), PostPO::getPostCode, postListParamPO.getPostCode())
.like(KPStringUtil.isNotEmpty(postListParamPO.getPostName()), PostPO::getPostName, postListParamPO.getPostName())
.eq(KPStringUtil.isNotEmpty(postListParamPO.getStatus()), PostPO::getStatus, postListParamPO.getStatus());
//分页和排序
PageHelper.startPage(postListParamPO.getPageNum(), postListParamPO.getPageSize(), postListParamPO.getOrderBy(PostPO.class));
return this.baseMapper.selectList(queryWrapper);
}
分页
- 如果不要分页 只要排序 则
- new PageBO().getOrderBy 固定写法
public List<DeptCustomerPO> queryList(DeptListParamPO deptListParamPO) {
PageHelper.orderBy(new PageBO().getOrderBy(deptListParamPO.getOrderBy(), DeptPO.class));
List<DeptCustomerPO> list = KPJsonUtil.toJavaObjectList(this.baseMapper.selectList(null), DeptCustomerPO.class);
}
PageHelper.orderBy(new PageBO().getOrderBy(deptListParamPO.getOrderBy(), DeptPO.class));
异常处理
- 框架提供了一些经常使用的异常类供用户使用
异常类 说明 KPServiceException 业务异常 KPUtilException 工具类异常 KPListenerDistributeException linener分发异常 KPHttpDistributeException HTTP请求异常