IDEA MyBatis Plugins自動(dòng)生成實(shí)體類和mapper.xml
前言
如何下載和使用MyBatis Generator 插件,只說代碼,不講感情。如果有問題還請(qǐng)多多指點(diǎn)。
開發(fā)環(huán)境
開發(fā)工具:IntelliJ IDEA 2018.1.1 x64 dk版本:1.8.0_171 工程構(gòu)建工具:maven 版本3.2.5 數(shù)據(jù)庫 mysqlIDEA 下載MyBatis Generator 插件
1.首先在File——Settings——點(diǎn)擊Plugins,搜索框中搜索mybatis,選擇mybatis-plugins,點(diǎn)擊安裝(由于我的已經(jīng)安裝過,所以沒有綠色的Install按鈕,而變成了instleaed,)安裝完成后點(diǎn)擊圖片上那個(gè)位置的按鈕(我忘了他叫什么了)之后會(huì)讓你重啟IDEA :
修改maven的pom文件
(注意此處是以plugin的方式,要放在plugins /plugins 里面)
<plugins> <!-- mybatis generator 自動(dòng)生成代碼插件 --> <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>
新建一個(gè)generatorConfig.xml
放入下方代碼,報(bào)錯(cuò)的話請(qǐ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):選擇你的本地硬盤上面的數(shù)據(jù)庫驅(qū)動(dòng)包--> <classPathEntry location='G:lianjieshujukuqudonglibmysql-connector-java-5.1.45-bin.jar'/> <context targetRuntime='MyBatis3'> <commentGenerator> <property name='suppressDate' value='true'/> <!-- 是否去除自動(dòng)生成的注釋 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是實(shí)體類名--> <table tableName='sc'domainObjectName='sc'enableCountByExample='false'enableUpdateByExample='false'enableDeleteByExample='false'enableSelectByExample='false'selectByExampleQueryId='false'> </table> </context></generatorConfiguration>
generatorConfig.xml中的注意事項(xiàng)xmlns報(bào)紅報(bào)錯(cuò)
解決辦法如下
file?>settings…?>languages & frameworks?>Schemas and DTDs?>點(diǎn)擊右邊的加號(hào)
那個(gè)xmlns報(bào)紅就添加那個(gè)URl數(shù)據(jù)庫驅(qū)動(dòng):選擇你的本地硬盤上面的數(shù)據(jù)庫驅(qū)動(dòng)包
數(shù)據(jù)驅(qū)動(dòng)包找不到在哪里的話在下載一個(gè),放到哪里看你心情嘍。這里只要這個(gè)驅(qū)動(dòng)包的位置真的找不到的話,這里有一個(gè)。
https://www.jb51.net/softs/214141.html
3.配置文件中需要修改的地方
運(yùn)行
Commang line:中的命令要輸入進(jìn)去
到此這篇關(guān)于IDEA MyBatis Plugins自動(dòng)生成實(shí)體類和mapper.xml的文章就介紹到這了,更多相關(guān)IDEA MyBatis Plugins自動(dòng)生成 內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. WML語言的基本情況2. CSS代碼檢查工具stylelint的使用方法詳解3. CSS3實(shí)例分享之多重背景的實(shí)現(xiàn)(Multiple backgrounds)4. html清除浮動(dòng)的6種方法示例5. 詳解CSS偽元素的妙用單標(biāo)簽之美6. div的offsetLeft與style.left區(qū)別7. 前端html+css實(shí)現(xiàn)動(dòng)態(tài)生日快樂代碼8. 使用css實(shí)現(xiàn)全兼容tooltip提示框9. 利用CSS3新特性創(chuàng)建透明邊框三角10. 不要在HTML中濫用div
