spawpaw / mybatis-generator-gui-extension

图形化MBG,内置丰富插件,可生成Service、Controller、View,配置简单。 A powerful GUI tool for MyBatisGenerator(MBG)
Other
642 stars 233 forks source link

生成mysql语句带表别名delete语法错误 #49

Closed weiguoxin closed 5 years ago

weiguoxin commented 5 years ago

mysql delete语句带别名正确的语句是 delete t from sys_permission t;

利用工具生成的delete语句是: delete from sys_permission t;

会报语法错误.

spawpaw commented 5 years ago

MySQL 的删除不就是DELETE FROM xxx WHERE xxx吗。。

weiguoxin commented 5 years ago

带表别名啊 delete from tablename t where xxx; 这样是报错的------------------ 原始邮件 ------------------ 发件人: "Ben"notifications@github.com 发送时间: 2019年7月8日(星期一) 晚上8:56 收件人: "spawpaw/mybatis-generator-gui-extension"mybatis-generator-gui-extension@noreply.github.com; 抄送: "weiguoxin"31655391@qq.com;"Author"author@noreply.github.com; 主题: Re: [spawpaw/mybatis-generator-gui-extension] 生成mysql语句带表别名delete语法错误 (#49)

spawpaw commented 5 years ago

这是个mybatis generator 的历史遗留问题,只有MySQL等部分数据库不支持这种语法,暂时没有好的解决方案,参考:https://github.com/mybatis/generator/issues/57

spawpaw commented 5 years ago

另外,下面是MBG中相关的代码: org.mybatis.generator.codegen.mybatis3.xmlmapper.elements.DeleteByExampleElementGenerator:46行

        StringBuilder sb = new StringBuilder();
        sb.append("delete from "); //$NON-NLS-1$
        sb.append(introspectedTable
                .getAliasedFullyQualifiedTableNameAtRuntime());//这里使用了带别名的表名进行生成

org.mybatis.generator.codegen.mybatis3.xmlmapper.elements.DeleteByPrimaryKeyElementGenerator:63行

        StringBuilder sb = new StringBuilder();
        sb.append("delete from "); //$NON-NLS-1$
        sb.append(introspectedTable.getFullyQualifiedTableNameAtRuntime());//这里没有使用带别名的表名
        answer.addElement(new TextElement(sb.toString()));

我翻阅了MBG的代码,发现应该可以做一些word around来修复这个问题,等明天看看

spawpaw commented 5 years ago

已经通过增加插件的方式来临时解决这个bug。 当选择了MySQL数据库,且更改了表别名时,以下配置会自动打开(也可以手动打开) image

生成的mapper: image

weiguoxin commented 5 years ago

这次弄好了