Mybatis-plus: 自定义SQL,${ew.customSqlSegment}问题

Created on 2 May 2019  ·  3Comments  ·  Source: baomidou/mybatis-plus

当前使用版本(必须填写清楚,否则不予处理)

3.1.1

该问题是怎么引起的?(最新版上已修复的会直接close掉)

根据官方文档
自定义sql + ${ew.customSqlSegment}
1.逻辑删除需要自己拼接条件 (之前自定义也同样)
2.不支持wrapper中附带实体的情况 (wrapper自带实体会更麻烦)
3.用法 ${ew.customSqlSegment} (不需要where标签包裹,切记!)
4.ew是wrapper定义别名,可自行替换。

无法自定义别名,是否底层源码中字符串"ew"二次覆盖?

重现步骤

@Select("SELECT * FROM tbl_employee ${guxiaotu.customSqlSegment}")
List<Employee> getAll(@Param("guxiaotu") Wrapper wrapper);

报错信息

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'ew' not found. Available parameters are [guxiaotu, param1]
.....
Caused by: org.apache.ibatis.binding.BindingException: Parameter 'ew' not found. Available parameters are [guxiaotu, param1]
    at org.apache.ibatis.binding.MapperMethod$ParamMap.get(MapperMethod.java:212)
    at org.apache.ibatis.reflection.wrapper.MapWrapper.get(MapWrapper.java:45)
    at org.apache.ibatis.reflection.MetaObject.getValue(MetaObject.java:122)

Most helpful comment

您好我也遇到了类似的问题但问题是由于想使用多个wrapper导致的,想使用多个wrapper的原因是因为在一个查询中有多个条件集,每个条件集我都想借用wrapper从而导致了类似的问题,我觉得支持多wrapper的使用后可以使xml的使用变得更少,还希望您能考虑。

All 3 comments

如果你要用 ew 之外的,那你构建的wrapper的属性paramAlias的值就必须跟着改变,目前这个属性不支持变更,也没有必要变更,所以不支持 ew 之外的

那属性值“ew”写死在哪个类中了?

您好我也遇到了类似的问题但问题是由于想使用多个wrapper导致的,想使用多个wrapper的原因是因为在一个查询中有多个条件集,每个条件集我都想借用wrapper从而导致了类似的问题,我觉得支持多wrapper的使用后可以使xml的使用变得更少,还希望您能考虑。

Was this page helpful?
0 / 5 - 0 ratings