这篇文章主要介绍了Mybatis-plus:${ew.sqlselect}用法说明,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
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字段后,查询对应的值
Mybatis-plus ${ew.sqlSegment}踩坑
使用${ew.sqlSegment} 如果是连表查询且查询条件是连表的字段则需在service层拼接查询条件时字段前指定别名
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程学习网。
沃梦达教程
本文标题为:Mybatis-plus:${ew.sqlselect}用法说明


猜你喜欢
- JSP 制作验证码的实例详解 2023-07-30
- Java实现顺序表的操作详解 2023-05-19
- JSP页面间传值问题实例简析 2023-08-03
- Java中的日期时间处理及格式化处理 2023-04-18
- 深入了解Spring的事务传播机制 2023-06-02
- ExecutorService Callable Future多线程返回结果原理解析 2023-06-01
- Spring Security权限想要细化到按钮实现示例 2023-03-07
- Springboot整合minio实现文件服务的教程详解 2022-12-03
- SpringBoot使用thymeleaf实现一个前端表格方法详解 2023-06-06
- 基于Java Agent的premain方式实现方法耗时监控问题 2023-06-17