0
点赞
收藏
分享

微信扫一扫

****************三层架构中类的参数注意事项

cwq聖泉寒江2020 2022-01-31 阅读 87
架构

1.在dao层 的接口类,添加@param()完成映射,在xml中就不需要写parametertype进行说明

2.在查询list操作中,一般都是加上三个参数,一个是前端的所有查询条件的一个总param参数,两个分页参数,pagenum,pagesize

public CommonResult<CommonPage<OmsOrder>> list(OmsOrderQueryParam queryParam,
 @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
  @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum) {
      List<OmsOrder> orderList = orderService.list(queryParam, pageSize, pageNum);}

3.在xml中使用<if test="queryParam.orderSn!=null and queryParam.orderSn!=''>

 and  order_sn = #{queryParam.orderSn}

</if>  完成条件的筛选

4.在模糊查询时候在xml中使用concat进行连接

<if test="queryParam.receiverKeyword!=null and queryParam.receiverKeyword!=''">
            AND (
            receiver_name LIKE concat("%",#{queryParam.receiverKeyword},"%")
            OR receiver_phone LIKE concat("%",#{queryParam.receiverKeyword},"%")
            )
        </if>

5.pagehelper 一般在serviceImpl实现类使用下边的这个,然后在使用dao层的方法进行查询

PageHelper.startPage(pageNum, pageSize); 使用了就是在下边的查询方法基础上进行分页

6.使用pageinfo对上边通过pagehelper查询出来的结果进行剥离数据

  /**
     * 将PageHelper分页后的list转为分页信息
     */
    public static <T> CommonPage<T> restPage(List<T> list) {
        CommonPage<T> result = new CommonPage<T>();
        PageInfo<T> pageInfo = new PageInfo<T>(list);
        result.setTotalPage(pageInfo.getPages());
        result.setPageNum(pageInfo.getPageNum());
        result.setPageSize(pageInfo.getPageSize());
        result.setTotal(pageInfo.getTotal());
        result.setList(pageInfo.getList());
        return result;
    }
举报

相关推荐

0 条评论