Mybatis-plus:${ew.sqlselect}用法

前言

上篇文章是通过动态注入的方式去筛选查询条件,这次我们用mybatis-plus自带的${ew.sqlselect}来筛选。
在这里插入图片描述
也就是Constants源码里的这个属性


一、使用步骤

1.在xml文件里引入

    <!--表数据list-->
    <select id="tableList" resultType="java.util.LinkedHashMap">
        SELECT
            ${ew.sqlSelect} // 这里拼接select后面的语句
        FROM
            ${table_name} //如果是单表的话,这里可以写死
        ${ew.customSqlSegment}
    </select>

2.mapper文件

 //表数据list
 IPage<LinkedHashMap<String,Object>> tableList(@Param("table_name") String table_name,
                                                  Page page,
                                                  @Param(Constants.WRAPPER) QueryWrapper queryWrapper);

3.用法

     String responseField = "*"; //先把拿到的值设为*,如果responsefield.equals或者为null,就使用默认值,这样就可以查询所有条件
        if (nativeWebRequest.getParameter("response_field") != null && !nativeWebRequest.getParameter("response_field").equals("")) {
            responseField = nativeWebRequest.getParameter("response_field");
        }
        if (responseField.length() != 0 && !"".equals(responseField)) {
            queryWrapper.select(responseField);
        }

不加入responsefield字段,或者responsefield字段为空时,查询所有的值在这里插入图片描述
加入responsefield字段后,查询对应的值
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值