IntelliJ IDEA(2019)之mybatis反向生成的實(shí)現(xiàn)
mybatis的逆向工程是非常便捷的操作,能夠顯著的提高我們的開發(fā)效率,之前介紹過Eclipse的操作,本文來介紹下在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ù)庫的驅(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ù)庫鏈接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.反向生成
生成的方式有多種,我們此處介紹一種簡便常用的方式,直接通過idea的plugin方式生成,如圖。
生成成功
最后生成好后將插件注釋掉即可
好了~搞定。以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Spring Security將用戶數(shù)據(jù)存儲(chǔ)到數(shù)據(jù)庫的方法
這篇文章主要介紹了Spring Security將用戶數(shù)據(jù)存儲(chǔ)到數(shù)據(jù)庫的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-09-09詳解springboot和vue前后端分離開發(fā)跨域登陸問題
這篇文章主要介紹了詳解springboot和vue前后端分離開發(fā)跨域登陸問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09Spring?Boot集成JasperReport生成文檔的方法
由于工作需要,要實(shí)現(xiàn)后端根據(jù)模板動(dòng)態(tài)填充數(shù)據(jù)生成PDF文檔,通過技術(shù)選型,使用Ireport5.6來設(shè)計(jì)模板,結(jié)合JasperReports5.6工具庫來調(diào)用渲染生成PDF文檔,這篇文章主要介紹了Spring?Boot集成JasperReport生成文檔,需要的朋友可以參考下2023-09-09Java實(shí)現(xiàn)較大二進(jìn)制文件的讀、寫方法
本篇文章主要介紹了Java實(shí)現(xiàn)較大二進(jìn)制文件的讀、寫方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-02-02關(guān)于SpringBoot的@ConfigurationProperties注解和松散綁定、數(shù)據(jù)校驗(yàn)
這篇文章主要介紹了關(guān)于SpringBoot的@ConfigurationProperties注解和松散綁定、數(shù)據(jù)校驗(yàn),@ConfigurationProperties主要作用就是將prefix屬性指定的前綴配置項(xiàng)的值綁定到這個(gè)JavaBean上?,通過指定的前綴,來綁定配置文件中的配置,需要的朋友可以參考下2023-05-05開源項(xiàng)目ERM模型轉(zhuǎn)jpa實(shí)體maven插件使用
這篇文章主要為大家介紹了開源項(xiàng)目ERM模型轉(zhuǎn)jpa實(shí)體maven插件的使用說明,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步2022-03-03SpringBoot實(shí)現(xiàn)elasticsearch索引操作的代碼示例
這篇文章主要給大家介紹了SpringBoot如何實(shí)現(xiàn)elasticsearch 索引操作,文中有詳細(xì)的代碼示例,感興趣的同學(xué)可以參考閱讀下2023-07-07Java 普通代碼塊靜態(tài)代碼塊執(zhí)行順序(實(shí)例講解)
下面小編就為大家?guī)硪黄狫ava 普通代碼塊靜態(tài)代碼塊執(zhí)行順序(實(shí)例講解)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-08-08Java自定義注解實(shí)現(xiàn)數(shù)據(jù)脫敏
在實(shí)際開發(fā)中經(jīng)常會(huì)遇到有一些信息不能全部展示用戶,需要隱藏(可以叫脫敏),所以本文為大家分享了利用自定義注解實(shí)現(xiàn)數(shù)據(jù)脫敏的示例代碼,需要的可以參考下2023-07-07