Mybatsi Generator生成mapper文件 关键字处理

xiaoxiao2025-04-07  25

1.问题描述,mybatsi的自动生成工具的方法,调用insert报错

2.解决办法,看到这种问题首先会想到sql语句报错

应为是使用的是:采用MyBatis Generator生成mapper文件,所以就是直接调用的方法,肯定是关键字出的问题,看了下Generator官网

http://www.mybatis.org/generator/configreference/context.html

autoDelimitKeywords 如果设置为true,MyBatis Generator (MBG)将会识别表的列明中的SQL关键字。如果个别关键字没有在MBG的的关键字列表里,可以通过<columnOverride>来界定。beginningDlimiter 开始的界定符,endingDelimiter设置结束界定符。

<context id="default" targetRuntime="MyBatis3"> <!-- optional,旨在创建class时,对注释进行控制 --> <commentGenerator> <!-- 自动识别数据库关键字,默认false --> <property name="autoDelimitKeywords" value="true" /> <!--可以使用``包括字段名,避免字段名与sql保留字冲突报错 --> <property name="beginningDelimiter" value="`" /> <property name="endingDelimiter" value="`" /> <property name="suppressDate" value="true"/> <property name="suppressAllComments" value="true"/> </commentGenerator>

可以解决问题

当然你要现修改 mapper呀 记得记上单引号

 

 

转载请注明原文地址: https://www.6miu.com/read-5027704.html

最新回复(0)