yulichang / mybatis-plus-join

支持连表查询的mybatis-plus,mybatis-plus风格的连表操作提供wrapper.leftJoin(),wrapper.rightJoin()等操作
https://yulichang.github.io/mybatis-plus-join-doc/
Apache License 2.0
971 stars 113 forks source link

实体类的字段名称如果不遵循首字母小写,而是首字母大时,执行查询时会报错 #91

Closed tangzixiong86 closed 6 months ago

tangzixiong86 commented 6 months ago

SYS_Station类的定义如下: @TableName("SYS_Station") @Data @ToString public class SYS_Station { @TableId private String Station_Code; private String dept_code; }

以下是测试代码: @Test public void test(){ MPJLambdaWrapper wrapper = new MPJLambdaWrapper<>(); wrapper.selectAll(SYS_USER.class) .innerJoin(SYS_Station.class,SYS_Station::getStation_Code,SYS_USER::getUSER_CODE); var users = _userMapper.selectJoinList(SYS_USER.class,wrapper); users.forEach(System.out::println); }

执行以上测试会报以下错误: Cannot invoke "com.github.yulichang.wrapper.segments.SelectCache.getColumn()" because the return value of "com.github.yulichang.wrapper.MPJAbstractLambdaWrapper.getCache(com.baomidou.mybatisplus.core.toolkit.support.SFunction)" is null

如果将Station类的Station_Code字段的名称,修改为首字母小写,则不会报错。

原因是MPJAbstractLambdaWrapper类以下方法: protected SelectCache getCache(SFunction<?, ?> fn) { Class<?> aClass = LambdaUtils.getEntityClass(fn); Map<String, SelectCache> cacheMap = ColumnCache.getMapField(aClass); return cacheMap.get(LambdaUtils.getName(fn)); } cacheMap中健值为Station_Code(首字母大写),LambdaUtils.getName(fn)方法得到的字段名为station_Code(首字母小写)

yulichang commented 6 months ago

好的,下个版本修复