IDEA MyBatis Plugins自動生成實體類和mapper.xml
前言
如何下載和使用MyBatis Generator 插件,只說代碼,不講感情。如果有問題還請多多指點。
開發(fā)環(huán)境
- 開發(fā)工具:IntelliJ IDEA 2018.1.1 x64
- dk版本:1.8.0_171
- 工程構(gòu)建工具:maven 版本3.2.5
- 數(shù)據(jù)庫 mysql
IDEA 下載MyBatis Generator 插件
1.首先在File——Settings——點擊Plugins,搜索框中搜索mybatis,選擇mybatis-plugins,點擊安裝(由于我的已經(jīng)安裝過,所以沒有綠色的Install按鈕,而變成了instleaed,)安裝完成后點擊圖片上那個位置的按鈕(我忘了他叫什么了)之后會讓你重啟IDEA :
修改maven的pom文件
(注意此處是以plugin的方式,要放在plugins /plugins 里面)
<plugins> <!-- mybatis generator 自動生成代碼插件 --> <plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <configuration> <!--配置文件的位置--> <configurationFile>src/main/resources/generatorConfig.xml</configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> </plugin> </plugins>
新建一個generatorConfig.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> <!-- 數(shù)據(jù)庫驅(qū)動:選擇你的本地硬盤上面的數(shù)據(jù)庫驅(qū)動包--> <classPathEntry location="G:\lianjieshujukuqudonglib\mysql-connector-java-5.1.45-bin.jar"/> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <!-- 是否去除自動生成的注釋 true:是 : false:否 --> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--數(shù)據(jù)庫鏈接URL,用戶名、密碼 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/xx" userId="root" password="root"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 生成模型的包名和位置--> <javaModelGenerator targetPackage="com.cn.wjp.springboot.entity" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成映射文件的包名和位置--> <sqlMapGenerator targetPackage="main.resources.mapping" targetProject="src"> <!-- enableSubPackages:是否讓schema作為包的后綴 --> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置--> <javaClientGenerator type="XMLMAPPER" targetPackage="com.cn.wjp.springboot.dao" targetProject="src/main/java"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- 要生成的表 tableName是數(shù)據(jù)庫中的表名或視圖名 domainObjectName是實體類名--> <table tableName="sc" domainObjectName="sc" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"> </table> </context> </generatorConfiguration>
generatorConfig.xml中的注意事項xmlns報紅報錯
解決辦法如下
file–>settings…–>languages & frameworks–>Schemas and DTDs–>點擊右邊的加號
那個xmlns報紅就添加那個URl數(shù)據(jù)庫驅(qū)動:選擇你的本地硬盤上面的數(shù)據(jù)庫驅(qū)動包
數(shù)據(jù)驅(qū)動包找不到在哪里的話在下載一個,放到哪里看你心情嘍。這里只要這個驅(qū)動包的位置
真的找不到的話,這里有一個。
http://www.dbjr.com.cn/softs/214141.html
3.配置文件中需要修改的地方
運(yùn)行
Commang line:中的命令要輸入進(jìn)去
到此這篇關(guān)于IDEA MyBatis Plugins自動生成實體類和mapper.xml的文章就介紹到這了,更多相關(guān)IDEA MyBatis Plugins自動生成 內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringBoot實現(xiàn)異步事件驅(qū)動的方法
本文主要介紹了SpringBoot實現(xiàn)異步事件驅(qū)動的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-06-06spring mvc中@RequestBody注解的作用說明
這篇文章主要介紹了spring mvc中@RequestBody注解的作用說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-08-08spring事務(wù)的REQUIRES_NEW源碼示例解析
這篇文章主要為大家介紹了spring事務(wù)的REQUIRES_NEW源碼示例解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09