IntelliJ IDEA(2019)之mybatis反向生成的實(shí)現(xiàn)
mybatis的逆向工程是非常便捷的操作,能夠顯著的提高我們的開(kāi)發(fā)效率,之前介紹過(guò)Eclipse的操作,本文來(lái)介紹下在idea中怎么處理。
mybatis逆向工程
1.配置文件
在resources目錄下創(chuàng)建配置文件,具體如下:
<?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> <!-- 數(shù)據(jù)庫(kù)的驅(qū)動(dòng)包路徑 --> <classPathEntry location="C:\Users\dengp\.m2\repository\mysql\mysql-connector-java\5.1.27\mysql-connector-java-5.1.27.jar" /> <context id="DB2Tables" targetRuntime="MyBatis3"> <!-- 去掉生成文件中的注釋 --> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 數(shù)據(jù)庫(kù)鏈接URL、用戶名、密碼 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/dpb-srm" userId="root" password="123456"> </jdbcConnection> <!-- <jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:XE" userId="car" password="car"> </jdbcConnection> --> <javaTypeResolver > <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成模型的包名和位置 當(dāng)前項(xiàng)目下 .\--> <javaModelGenerator targetPackage="com.sxt.sys.pojo" targetProject=".\src\main\java"> <!-- 是否在當(dāng)前路徑下新加一層schema,eg:fase路徑com.oop.eksp.user.model, true:com.oop.eksp.user.model.[schemaName] --> <property name="enableSubPackages" value="false" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources"> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.sxt.sys.mapper" targetProject=".\src\main\java"> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <table tableName="t_emp" domainObjectName="Emp" schema=""></table> <table tableName="t_basic" domainObjectName="Basic" schema=""></table> <table tableName="t_dept" domainObjectName="Dept" schema=""></table> <table tableName="t_role" domainObjectName="Role" schema=""></table> <table tableName="t_user" domainObjectName="User" schema=""></table> <table tableName="t_menu" domainObjectName="Menu" schema=""></table> </context> </generatorConfiguration>
2.插件依賴
在pom.xml文件中添加mybatis的generator插件。具體如下:
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <!--關(guān)聯(lián)上面的配置文件 --> <configurationFile>src/main/resources/mybatis-generator/generatorConfig-sys.xml</configurationFile> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <executions> <execution> <id>Generate MyBatis Artifacts</id> <goals> <goal>generate</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> </dependencies> </plugin>
3.反向生成
生成的方式有多種,我們此處介紹一種簡(jiǎn)便常用的方式,直接通過(guò)idea的plugin方式生成,如圖。
生成成功
最后生成好后將插件注釋掉即可
好了~搞定。以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
SpringBoot對(duì)靜態(tài)資源的映射規(guī)則詳解解讀
這篇文章主要介紹了SpringBoot對(duì)靜態(tài)資源的映射規(guī)則詳解解讀,在Spring Boot中,映射規(guī)則是用來(lái)定義URL與控制器方法之間的映射關(guān)系的,通過(guò)映射規(guī)則,可以將特定的URL請(qǐng)求映射到相應(yīng)的控制器方法上,從而實(shí)現(xiàn)請(qǐng)求的處理和響應(yīng)的返回,需要的朋友可以參考下2023-10-10mybatis中字段名與關(guān)鍵字相同問(wèn)題
這篇文章主要介紹了mybatis中字段名與關(guān)鍵字相同問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02springboot整合騰訊云短信開(kāi)箱即用的示例代碼
這篇文章主要介紹了springboot整合騰訊云短信開(kāi)箱即用,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-03-03Spring Boot框架中的@Conditional注解示例詳解
這篇文章主要介紹了Spring Boot框架中的@Conditional系列注解,@ConditionalOnProperty注解的作用是解析application.yml/application.properties 里的配置生成條件來(lái)生效,也是與@Configuration注解一起使用,本文通過(guò)示例代碼給大家介紹的非常詳細(xì),需要的朋友一起看看吧2022-09-09IDEA中程序包Org.Springframework.Boot不存在問(wèn)題及解決
這篇文章主要介紹了IDEA中程序包Org.Springframework.Boot不存在問(wèn)題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-07-07Java實(shí)現(xiàn)將類(lèi)數(shù)據(jù)逐行寫(xiě)入CSV文件的方法詳解
這篇文章主要為大家詳細(xì)介紹了Java如何實(shí)現(xiàn)將類(lèi)數(shù)據(jù)逐行寫(xiě)入CSV文件,文中的示例代碼講解詳細(xì),具有一定的參考價(jià)值,需要的可以借鑒一下2022-11-11Springboot中的@ComponentScan注解使用解析
這篇文章主要介紹了Springboot中的@ComponentScan注解使用解析,@ComponentScan用于類(lèi)或接口上主要是指定掃描路徑,spring會(huì)把指定路徑下帶有指定注解的類(lèi)注冊(cè)到IOC容器中,需要的朋友可以參考下2024-01-01