ruoyi在接口controller层级设置body请求参数,page分页和params,PageHelper重复使用

需求背景,写了个联合接口,需要自定义body请求参数,page分页和params

看代码

@PostMapping("/xxx")
    public AjaxResult xxx(HttpServletRequest request){
        AjaxResult ajax = AjaxResult.success();
        OrderGift orderGift_top = new OrderGift();
        OrderGift orderGift_normal = new OrderGift();
        String shopId = "11"
        ConfigGlobal sysConfigGlobal = configGlobalService.selectConfigGlobalByShopId(shopId);
        if(sysConfigGlobal != null && sysConfigGlobal.getGiftShowTopStatus().equals(UserConstants.YES)){
            PageHelper.startPage(1, 3).setReasonable(true);
            // desc为降序,asc为升序
            PageHelper.orderBy("init_amount desc");
            Map<String, Object> params_top = new HashMap<>();
            String endTime = MyUtils.dateToStrLong(new Date());
            int giftRecentDay = 7;
            String beginTime = MyUtils.getBeforeDay(endTime, giftRecentDay);
            params_top.put("beginTime", beginTime);
            params_top.put("endTime", endTime);
            orderGift_top.setParams(params_top);

            List<OrderGift> topList = orderGiftService.selectOrderGiftList(orderGift_top);
            ajax.put("topList", topList);
        }

        PageHelper.clearPage();

        int pageNum = 10;
        BigDecimal giftShowMin = new BigDecimal(0);
        Map<String, Object> params_normal = new HashMap<>();
        if(sysConfigGlobal != null){
            pageNum = sysConfigGlobal.getGiftShowCount();
            giftShowMin = sysConfigGlobal.getGiftShowMin();
        }
        params_normal.put("minAmount", giftShowMin);
        orderGift_normal.setParams(params_normal);
        PageHelper.startPage(1, pageNum).setReasonable(true);

        List<OrderGift> giftList = orderGiftService.selectOrderGiftList(orderGift_normal);
        ajax.put("giftList", giftList);
        return ajax;
    }

mybatis中xml的代码 


    <select id="selectOrderGiftList" parameterType="OrderGift" resultMap="OrderGiftResult">
		<include refid="selectOrderGiftVo"/>
		where 1 = 1
		<if test="orderNo != null and orderNo != ''">
			AND o.order_no like concat('%', #{orderNo}, '%')
		</if>
		<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
			AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
		</if>
		<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
			AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
		</if>
		<if test="params.minAmount != null"><!-- 最小金额检索 -->
			AND #{params.minAmount} &lt;= o.init_amount
		</if>
		<!-- 数据范围过滤 -->
		${params.dataScope}
	</select>
自定义分页:
PageHelper.startPage(1, 5).setReasonable(true); 

// desc为降序,asc为升序 自定义排序:
PageHelper.orderBy("init_amount desc");

清除当前线程的分页参数
PageHelper.clearPage();
 /**
     * 封装分页对象 会读取客户端传来的pageSize,客户端没传,会默认10条 
     */
    public static PageDomain getPageDomain()
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameter(PAGE_NUM), 1));
        pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameter(PAGE_SIZE), 10));
        pageDomain.setOrderByColumn(ServletUtils.getParameter(ORDER_BY_COLUMN));
        pageDomain.setIsAsc(ServletUtils.getParameter(IS_ASC));
        pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
        return pageDomain;
    }

/**
     * 封装分页对象 会读取客户端传来的pageSize,客户端没传,会默认10条
     */
    public static PageDomain getPageDomainByPost()
    {
        PageDomain pageDomain = new PageDomain();
        pageDomain.setPageNum(Convert.toInt(ServletUtils.getParameterByPost(PAGE_NUM), 1));
        pageDomain.setPageSize(Convert.toInt(ServletUtils.getParameterByPost(PAGE_SIZE), 10));
        pageDomain.setOrderByColumn(ServletUtils.getParameterByPost(ORDER_BY_COLUMN));
        pageDomain.setIsAsc(ServletUtils.getParameterByPost(IS_ASC));
        pageDomain.setReasonable(ServletUtils.getParameterToBool(REASONABLE));
        return pageDomain;
    }
问题:

由于我自定义的方法startPageByPost(),看代码中的initAmount,因为startPageByPost()方法会将前端传来的驼峰写法改成下划线,init_amount

我一开始这么写
PageHelper.orderBy("initAmount desc");
startPageByPost()

结果:就会导致pageSize不生效

如果去掉startPageByPost(),变成这么写
PageHelper.orderBy("initAmount desc");

就会提示 initAmount 未定义


结论:
不需要startPageByPost()方法,手动修改成下划线写法,对应数据库的字段名
PageHelper.orderBy("init_amount desc");

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值