IDEA MyBatis Plugins自動(dòng)生成實(shí)體類和mapper.xml
前言
如何下載和使用MyBatis Generator 插件,只說(shuō)代碼,不講感情。如果有問(wèn)題還請(qǐng)多多指點(diǎn)。
開(kāi)發(fā)環(huán)境
開(kāi)發(fā)工具:IntelliJ IDEA 2018.1.1 x64 dk版本:1.8.0_171 工程構(gòu)建工具:maven 版本3.2.5 數(shù)據(jù)庫(kù) mysqlIDEA 下載MyBatis Generator 插件
1.首先在File——Settings——點(diǎn)擊Plugins,搜索框中搜索mybatis,選擇mybatis-plugins,點(diǎn)擊安裝(由于我的已經(jīng)安裝過(guò),所以沒(méi)有綠色的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ù)庫(kù)驅(qū)動(dòng):選擇你的本地硬盤上面的數(shù)據(jù)庫(kù)驅(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ù)庫(kù)鏈接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ù)庫(kù)中的表名或視圖名 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ù)庫(kù)驅(qū)動(dòng):選擇你的本地硬盤上面的數(shù)據(jù)庫(kù)驅(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. phpstudy apache開(kāi)啟ssi使用詳解2. vue3+ts+elementPLus實(shí)現(xiàn)v-preview指令3. Xml簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理4. JSP之表單提交get和post的區(qū)別詳解及實(shí)例5. 詳解瀏覽器的緩存機(jī)制6. xml中的空格之完全解說(shuō)7. jsp實(shí)現(xiàn)登錄驗(yàn)證的過(guò)濾器8. jsp文件下載功能實(shí)現(xiàn)代碼9. 使用Hangfire+.NET 6實(shí)現(xiàn)定時(shí)任務(wù)管理(推薦)10. 如何在jsp界面中插入圖片
