IDEA MyBatis Plugins自动生成实体类和mapper.xml
作者:漫天乱舞的三轮车 时间:2021-07-24 01:26:37
前言
如何下载和使用MyBatis Generator 插件,只说代码,不讲感情。如果有问题还请多多指点。
开发环境
开发工具:IntelliJ IDEA 2018.1.1 x64
dk版本:1.8.0_171
工程构建工具:maven 版本3.2.5
数据库 mysql
IDEA 下载MyBatis Generator 插件
1.首先在File——Settings——点击Plugins,搜索框中搜索mybatis,选择mybatis-plugins,点击安装(由于我的已经安装过,所以没有绿色的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>
<!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->
<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>
<!--数据库链接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是数据库中的表名或视图名 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数据库驱动:选择你的本地硬盘上面的数据库驱动包
数据驱动包找不到在哪里的话在下载一个,放到哪里看你心情喽。这里只要这个驱动包的位置
真的找不到的话,这里有一个。
https://www.jb51.net/softs/214141.html
3.配置文件中需要修改的地方
运行
Commang line:中的命令要输入进去
来源:https://blog.csdn.net/qq_43583597/article/details/89294963
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java泛型变量如何添加约束
SpringBoot防止大量请求攻击的实现
![](https://img.aspxhome.com/file/2023/1/59731_0s.jpg)
java多线程和并发包入门示例
Mybatis环境搭建及文件配置过程解析
![](https://img.aspxhome.com/file/2023/4/75504_0s.png)
浅谈JVM之使用JFR解决内存泄露
![](https://img.aspxhome.com/file/2023/3/81953_0s.jpg)
用Flutter开发自定义Plugin的方法示例
![](https://img.aspxhome.com/file/2023/3/99793_0s.png)
Java实现的断点续传功能的示例代码
SpringCloud eureka(server)微服务集群搭建过程
![](https://img.aspxhome.com/file/2023/4/69104_0s.jpg)
C#中使用@声明变量示例(逐字标识符)
SpringBoot配置文件中密码属性加密的实现
![](https://img.aspxhome.com/file/2023/8/64018_0s.jpg)
Unity键盘WASD实现物体移动
![](https://img.aspxhome.com/file/2023/3/71073_0s.jpg)
Spring Boot + Mybatis 实现动态数据源案例分析
![](https://img.aspxhome.com/file/2023/0/77440_0s.png)
Java Springboot整合支付宝接口的教程详解
![](https://img.aspxhome.com/file/2023/9/58749_0s.png)
原生Java操作兔子队列RabbitMQ
![](https://img.aspxhome.com/file/2023/9/70559_0s.png)
浅谈Java常见的排序算法
![](https://img.aspxhome.com/file/2023/0/63640_0s.png)
ToStringBuilder类的一些心得
Spring中的bean概念介绍
![](https://img.aspxhome.com/file/2023/3/71863_0s.png)
Idea servlet映射方法优缺点对比
![](https://img.aspxhome.com/file/2023/8/63298_0s.png)
C#读写INI文件的方法
Java在制作jar包时引用第三方jar包的方法
![](https://img.aspxhome.com/file/2023/2/83042_0s.png)