当前使用版本(必填,否则不予处理)
3.4.1版本
该问题是如何引起的?(确定最新版也有问题再提!!!)
生成sql 少了and连接符
重现步骤(如果有就写完整)
Wrappers.query(param).lambda().ge(Objects.nonNull(startDate), OrderCheckDetail::getTransDate, startDate);
报错信息
请求url /page?current=1&size=10&startDate=2020-12-30&endDate=2021-06-30&paySn=%20
paySn 在param 字段 paySn = %20空格字符串,报错
生成的 sql WHERE pay_sn = ? (trans_date >= ? AND trans_date <= ?) ORDER BY trans_date DESC 中 少了and 。。。。。
这种怎么解决
Comment From: lw201608
什么时候看看这个问题嘛
Comment From: lw201608
一个星期过去了
Comment From: lw201608
((LambdaQueryWrapper)(((ParamMap) args[1]).get("param2"))).nonEmptyOfEntity(); // false
导致 ew.nonEmptyOfEntity and ew.nonEmptyOfNormal = false 缺少了and
Comment From: lw201608
执行的代码Wrapper.nonEmptyOfEntity(); //false
public boolean nonEmptyOfEntity() { T entity = getEntity(); if (entity == null) { return false; } TableInfo tableInfo = TableInfoHelper.getTableInfo(entity.getClass()); if (tableInfo == null) { return false; } if (tableInfo.getFieldList().stream().anyMatch(e -> fieldStrategyMatch(entity, e))) { return true; } return StringUtils.isNotBlank(tableInfo.getKeyProperty()) ? Objects.nonNull(ReflectionKit.getFieldValue(entity, tableInfo.getKeyProperty())) : false; }
代码出现问题 在 tableInfo.getFieldList().stream().anyMatch(e -> fieldStrategyMatch(entity, e)))
case NOT_EMPTY: return com.baomidou.mybatisplus.core.toolkit.StringUtils.checkValNotNull(ReflectionKit.getFieldValue(entity, e.getProperty()));
调用 isNotBlank()
而 entity.paySn = " "; 存在属性
综合以上
输出了 sql where一段: pay_sn= ‘ ’ ${ew.sqlSegment}
由于缺少and ,sql 报错
Comment From: lw201608
。。。 只能 覆盖 类com.baomidou.mybatisplus.core.toolkit.StringUtils 修改checkValNotNull
public static boolean checkValNotNull(Object object) { if (object instanceof CharSequence) { return isNotEmpty((CharSequence) object); } return object != null; }
Comment From: qmdx
请关注 3.4.3.2 版本发布 https://github.com/baomidou/mybatis-plus/commit/06fb204908d9e323704887db096ffac1bdf1d1a1