解決myBatis generator逆向生成沒有根據(jù)主鍵的select,update和delete問題
一、配置逆向generatoe.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd"> <generatorConfiguration> <context id="DB2Tables" targetRuntime="MyBatis3"> <!-- 是否生成注釋 --> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 配置數(shù)據(jù)庫連接信息 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/ssm_crud?serverTimezone=UTC" userId="root" password="root"> <!--<property name="useInformationSchema" value="true"/>--> </jdbcConnection> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 指定javaBean生成的位置 --> <javaModelGenerator targetPackage="com.atguigu.crud.bean" targetProject=".\src\main\java"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 指定sql映射文件生成的位置 --> <sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 指定dao接口生成位置,mapper接口 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.atguigu.crud.dao" targetProject=".\src\main\java"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- table指定每個表的生成策略 --> <table tableName="tbl_emp" domainObjectName="Employee" /> <table tableName="tbl_dept" domainObjectName="Department" /> </context> </generatorConfiguration>
二、執(zhí)行生成代碼
public class MBGTest { public static void main(String[] args) throws Exception{ List<String> warnings = new ArrayList<String>(); boolean overwrite = true; File configFile = new File("mbg.xml"); ConfigurationParser cp = new ConfigurationParser(warnings); Configuration config = cp.parseConfiguration(configFile); DefaultShellCallback callback = new DefaultShellCallback(overwrite); MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings); myBatisGenerator.generate(null); } }
三、結(jié)果mapper中未能生成...ByPrimaryKey的方法
四、解決辦法
在generatoe.xml的配置數(shù)據(jù)庫連接信息時,添加
<property name="useInformationSchema" value="true"/>
即可解決問題
以上這篇解決myBatis generator逆向生成沒有根據(jù)主鍵的select,update和delete問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot使用Graylog日志收集的實現(xiàn)示例
Graylog是一個生產(chǎn)級別的日志收集系統(tǒng),集成Mongo和Elasticsearch進行日志收集,這篇文章主要介紹了SpringBoot使用Graylog日志收集的實現(xiàn)示例,感興趣的小伙伴們可以參考一下2019-04-04SpringBoot繼承LogStash實現(xiàn)日志收集的方法示例
這篇文章主要介紹了SpringBoot繼承LogStash實現(xiàn)日志收集的方法示例,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-05-05Spring Task定時任務(wù)每天零點執(zhí)行一次的操作
這篇文章主要介紹了Spring Task定時任務(wù)每天零點執(zhí)行一次的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-09-09SpringBoot基于Redis實現(xiàn)短信登錄的操作
驗證碼登錄是非常常見的一種登錄方式,能夠簡化用戶登錄的過程,本文主要介紹了SpringBoot基于Redis實現(xiàn)短信登錄的操作,具有一定的參考價值,感興趣的可以了解一下2023-12-12