登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
代码拉取完成,页面将自动刷新
开源项目
>
数据库相关
>
数据库开发包
&&
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
2.3K
Star
11.6K
Fork
3.5K
GVP
baomidou
/
mybatis-plus
代码
Issues
13
Pull Requests
0
统计
流水线
服务
JavaDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
is打头的Boolean字段导致的代码生成器与lambda构造器的冲突
已完成
#I1JXCX
WangZhiyuan
创建于
2020-06-08 17:55
### 当前使用版本(必填,否则不予处理) mybatis-plus-generator: 3.3.2 mybatis-plus: 3.3.2 ### 该问题是如何引起的?(确定最新版也有问题再提!!!) 代码生成器生成 **is打头的 Boolean字段** 时,该字段不能用于 **Lambda相关构造器** 。 会报can not find lambda cache for this property cctvMonitor of entity [%s] 原因: 代码生成器对is打头对Boolean字段生成结果如下,属性有is前缀,get/set去掉了is ``` /** * 是否CCTV监控 */ @TableField("IS_CCTV_MONITOR") private Boolean isCctvMonitor; public Boolean getCctvMonitor() { return isCctvMonitor; } public void setCctvMonitor(Boolean isCctvMonitor) { this.isCctvMonitor = isCctvMonitor; } ``` 代码生成器里的相关代码 1. com.baomidou.mybatisplus.generator.config.po.TableField#getCapitalName // 这个方法会去掉boolean类型的is前缀 ``` public String getCapitalName() { if (this.propertyName.length() <= 1) { return this.propertyName.toUpperCase(); } else { String setGetName = this.propertyName; if (DbColumnType.BASE_BOOLEAN.getType().equalsIgnoreCase(this.columnType.getType())) { setGetName = StringUtils.removeIsPrefixIfBoolean(setGetName, Boolean.class); } String firstChar = setGetName.substring(0, 1); return Character.isLowerCase(firstChar.toCharArray()[0]) && Character.isUpperCase(setGetName.substring(1, 2).toCharArray()[0]) ? firstChar.toLowerCase() + setGetName.substring(1) : firstChar.toUpperCase() + setGetName.substring(1); } } ``` 使用lambda相关构造器XXX::getCctvMonitor时,会去columnMap中找CCTVMONITOR,而这个字段在columnMap中的key是ISCCTVMONITOR 2. com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper#getColumn ``` private String getColumn(SerializedLambda lambda, boolean onlyColumn) throws MybatisPlusException { String fieldName = PropertyNamer.methodToProperty(lambda.getImplMethodName());// **这里是从方法名反推属性名** ,因此这里的fieldName = "cctvMonitor" Class<?> aClass = lambda.getInstantiatedType(); if (!this.initColumnMap) { this.columnMap = LambdaUtils.getColumnMap(aClass);// **columnMap中存的key是从类的属性名取的** ,因此是 ISCCTVMONITOR this.initColumnMap = true; } Assert.notNull(this.columnMap, "can not find lambda cache for this entity [%s]", new Object[]{aClass.getName()}); ColumnCache columnCache = (ColumnCache)this.columnMap.get(LambdaUtils.formatKey(fieldName)); // CCTVMONITOR 和 ISCCTVMONITOR不匹配,然后断言失败 Assert.notNull(columnCache, "can not find lambda cache for this property [%s] of entity [%s]", new Object[]{fieldName, aClass.getName()}); return onlyColumn ? columnCache.getColumn() : columnCache.getColumnSelect(); } ``` ### 重现步骤(如果有就写完整) ### 报错信息 can not find lambda cache for this property cctvMonitor of entity [%s] ### 也许是个方案? 因为有根据get方法反推属性名的逻辑在,所以我个人认为修改generator里的getCapitalName方法比较合理, **删掉removeIsPrefixIfBoolean这个分支,无脑大写第一个字符就行了?** 。 现在我是把代码生成器里的Boolean值全部替换成了Integer。 如果我这边数据库字段里没有IS_24_SECURITY这种字段,其实我给代码生成器设置下setEntityBooleanColumnRemoveIsPrefix(true);也不会出现这个问题。 但是我左思右想觉得,getCapitalName里去掉is好像没什么必要? 一个小点,希望大佬们评审下。
### 当前使用版本(必填,否则不予处理) mybatis-plus-generator: 3.3.2 mybatis-plus: 3.3.2 ### 该问题是如何引起的?(确定最新版也有问题再提!!!) 代码生成器生成 **is打头的 Boolean字段** 时,该字段不能用于 **Lambda相关构造器** 。 会报can not find lambda cache for this property cctvMonitor of entity [%s] 原因: 代码生成器对is打头对Boolean字段生成结果如下,属性有is前缀,get/set去掉了is ``` /** * 是否CCTV监控 */ @TableField("IS_CCTV_MONITOR") private Boolean isCctvMonitor; public Boolean getCctvMonitor() { return isCctvMonitor; } public void setCctvMonitor(Boolean isCctvMonitor) { this.isCctvMonitor = isCctvMonitor; } ``` 代码生成器里的相关代码 1. com.baomidou.mybatisplus.generator.config.po.TableField#getCapitalName // 这个方法会去掉boolean类型的is前缀 ``` public String getCapitalName() { if (this.propertyName.length() <= 1) { return this.propertyName.toUpperCase(); } else { String setGetName = this.propertyName; if (DbColumnType.BASE_BOOLEAN.getType().equalsIgnoreCase(this.columnType.getType())) { setGetName = StringUtils.removeIsPrefixIfBoolean(setGetName, Boolean.class); } String firstChar = setGetName.substring(0, 1); return Character.isLowerCase(firstChar.toCharArray()[0]) && Character.isUpperCase(setGetName.substring(1, 2).toCharArray()[0]) ? firstChar.toLowerCase() + setGetName.substring(1) : firstChar.toUpperCase() + setGetName.substring(1); } } ``` 使用lambda相关构造器XXX::getCctvMonitor时,会去columnMap中找CCTVMONITOR,而这个字段在columnMap中的key是ISCCTVMONITOR 2. com.baomidou.mybatisplus.core.conditions.AbstractLambdaWrapper#getColumn ``` private String getColumn(SerializedLambda lambda, boolean onlyColumn) throws MybatisPlusException { String fieldName = PropertyNamer.methodToProperty(lambda.getImplMethodName());// **这里是从方法名反推属性名** ,因此这里的fieldName = "cctvMonitor" Class<?> aClass = lambda.getInstantiatedType(); if (!this.initColumnMap) { this.columnMap = LambdaUtils.getColumnMap(aClass);// **columnMap中存的key是从类的属性名取的** ,因此是 ISCCTVMONITOR this.initColumnMap = true; } Assert.notNull(this.columnMap, "can not find lambda cache for this entity [%s]", new Object[]{aClass.getName()}); ColumnCache columnCache = (ColumnCache)this.columnMap.get(LambdaUtils.formatKey(fieldName)); // CCTVMONITOR 和 ISCCTVMONITOR不匹配,然后断言失败 Assert.notNull(columnCache, "can not find lambda cache for this property [%s] of entity [%s]", new Object[]{fieldName, aClass.getName()}); return onlyColumn ? columnCache.getColumn() : columnCache.getColumnSelect(); } ``` ### 重现步骤(如果有就写完整) ### 报错信息 can not find lambda cache for this property cctvMonitor of entity [%s] ### 也许是个方案? 因为有根据get方法反推属性名的逻辑在,所以我个人认为修改generator里的getCapitalName方法比较合理, **删掉removeIsPrefixIfBoolean这个分支,无脑大写第一个字符就行了?** 。 现在我是把代码生成器里的Boolean值全部替换成了Integer。 如果我这边数据库字段里没有IS_24_SECURITY这种字段,其实我给代码生成器设置下setEntityBooleanColumnRemoveIsPrefix(true);也不会出现这个问题。 但是我左思右想觉得,getCapitalName里去掉is好像没什么必要? 一个小点,希望大佬们评审下。
评论 (
5
)
登录
后才可以发表评论
状态
已完成
待办的
进行中
已完成
已关闭
负责人
未设置
你有医保你先上
h825944942
负责人
协作者
+负责人
+协作者
聂秋荣
nieqiurong
负责人
协作者
+负责人
+协作者
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (4)
标签 (63)
3.0
master
2.x
1.x
v3.5.5
v3.5.3.2
v3.5.3.1
v3.5.3
3.5.2
v3.5.1
v3.4.3.2
v3.4.2
v3.4.3.1
v3.4.3
v3.4.1
v3.4.0
v3.3.2
v3.3.1.tmp
v3.3.1
v3.3.0
v3.2.1.1-SNAPSHOT
v3.2.0
v3.1.2
v3.1.1
v3.1.0
v3.0.4
v2.3.2
v3.0.2
v.2.3.1
v3.0.1
v3.0-RELEASE
v3.0-RC2
v3.0-RC1
v3.0-RC
v3.0-gamma
v3.0-beta
v3.0-alpha
v2.3
v2.2.0
v2.1.9
v2.1.8
v2.1.7
v2.1.5
v.2.1.3
v2.1.2
v2.1.1
v2.1.0
v2.0.9
v2.0.8
v2.0.6
v2.0.5
v2.0.3
v2.0.2
v2.0.1
v2.0
v2.0-beta
v1.4.9
v1.4.8
v1.4.7
v1.4.6
v1.4.5
v1.4.3
v1.4.0
v1.3.0
v1.2.1
v1.1
v1.0
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(2)
Java
1
https://gitee.com/baomidou/mybatis-plus.git
git@gitee.com:baomidou/mybatis-plus.git
baomidou
mybatis-plus
mybatis-plus
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册