MyBatis Generator使用方法
2024-09-08 19:42:47
第一步:在resources
文件夹下创建一个目录mybatis-generator
,在目录mybatis-generator
下创建文件generatorConfig.xml
(此处的目录名可任意取)
第二步:在pom文件标签<plugins>处引入依赖
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<configurationFile>${basedir}/src/main/resources/mybatis-generator/generatorConfig.xml
</configurationFile>
<overwrite>true</overwrite>
<verbose>true</verbose>
</configuration>
</plugin>
第三步:配置generatorConfig.xml
注:①标红处即为需要修改处
②"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd" 在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>
<!-- 连接数据库jar包的路径-->
<classPathEntry location="/Users/dxm1/.m2/repository/mysql/mysql-connector-java/5.1.48/mysql-connector-java-5.1.48.jar"/>
<context id="DB2Tables" targetRuntime="MyBatis3">
<commentGenerator>
<property name="suppressDate" value="true"/>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator> <!--数据库连接参数 -->
<jdbcConnection
driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/test_db?serverTimezone=UTC&useSSL=false"
userId="root"
password="zu273334ly">
</jdbcConnection> <javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver> <!-- 实体类的包名和存放路径 -->
<javaModelGenerator targetPackage="com.example.demo.model" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
<property name="trimStrings" value="true"/>
</javaModelGenerator> <!-- 生成映射文件*.xml的位置-->
<sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
<property name="enableSubPackages" value="true"/>
</sqlMapGenerator> <!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.example.demo.dao" targetProject="src/main/java">
<property name="enableSubPackages" value="true"/>
</javaClientGenerator> <!-- tableName:数据库中的表名或视图名;domainObjectName:生成的实体类的类名-->
<table tableName="GENERAL_BALANCE_PLAN" domainObjectName="GeneralBalancePlan"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
<!--
<table tableName="xxx" domainObjectName="xxx"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
...
<table tableName="xxx" domainObjectName="xxx"
enableCountByExample="false"
enableUpdateByExample="false"
enableDeleteByExample="false"
enableSelectByExample="false"
selectByExampleQueryId="false"/>
-->
</context>
</generatorConfiguration>
如何找连接数据库jar包的路径,可参考 https://blog.csdn.net/weixin_43228497/article/details/83114594
第四步:启动
参考资料: https://blog.csdn.net/weixin_42250302/article/details/106986707
最新文章
- 用alarmmanager 多次发送PendingIntent
- mysql配置文件编写
- discuz不能发表投票、附件上传等
- 预写式日志(Write-Ahead Logging (WAL))
- selenium处理rich text(富文本框)
- Putty &; Ctrl+s 的魔咒
- ORA-00257错误
- HDU 5701 中位数计数 暴力
- margin设置为负数
- 求1+2+3+...+n的值,要求不能使用乘除法,for、while、if、else、switch、case、等关键字及条件判断语句(JAVA)
- [C++]unordered_map的使用
- lpr
- 如何给自己的外包APP开发报价?
- Vue框架之双向绑定事件
- C#模板设计模式使用和学习心得
- mysql 数据库的数据类型
- 一个很适合初学者的selenium教程
- 出现 The processing instruction target matching ";[xX][mM][lL]"; is not allowed错误
- data warehouse 1.0 vs 2.0
- IntelliJ IDEA Tomcat中端口被占用的问题