我是靠谱客的博主 酷炫小懒虫,这篇文章主要介绍mybatis 代码生成器,现在分享给大家,希望可以做个参考。

MyBatis Generator

能够自动生成 mapper文件,entity实体类等,方便开发人员使用。

引入的依赖、插件

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.5</version> <configuration> <configurationFile>D:ideaProjectwhale-userwhale-user-coresrcmainresourcesmybatis-generatorgeneratorConfig.xml </configurationFile> <overwrite>true</overwrite> <verbose>true</verbose> </configuration> </plugin>

注意配置文件地址可能需要修改

添加配置文件

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?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="D:repositoryorgmariadbjdbcmariadb-java-client2.1.2mariadb-java-client-2.1.2.jar"/> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressDate" value="true"/> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true"/> </commentGenerator> <!--数据库连接参数 --> <jdbcConnection driverClass="org.mariadb.jdbc.Driver" connectionURL="jdbc:mariadb://172.0.0.1:3306/test?characterEncoding=UTF-8" userId="root" password="111111"> </jdbcConnection> <javaTypeResolver> <property name="forceBigDecimals" value="false"/> </javaTypeResolver> <!-- 实体类的包名和存放路径 --> <javaModelGenerator targetPackage="com.sensetime.scg.whale.user.entity" targetProject="D:ideaProjectwhale-userwhale-user-clientsrcmainjava"> <property name="enableSubPackages" value="true"/> <property name="trimStrings" value="true"/> </javaModelGenerator> <!-- 生成映射文件*.xml的位置--> <sqlMapGenerator targetPackage="mapper" targetProject="D:ideaProjectwhale-userwhale-user-coresrcmainresources"> <property name="enableSubPackages" value="true"/> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="com.sensetime.scg.whale.user.dao" targetProject="D:ideaProjectwhale-userwhale-user-coresrcmainjava"> <property name="enableSubPackages" value="true"/> </javaClientGenerator> <!-- tableName:数据库中的表名或视图名;domainObjectName:生成的实体类的类名--> <table tableName="info_resource" domainObjectName="Resource" 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>

生成的文件在按照自己的项目结构自己定义,此处我使用的是绝对路径

在这里插入图片描述

执行生成

双击插件就可以执行
在这里插入图片描述

最后

以上就是酷炫小懒虫最近收集整理的关于mybatis 代码生成器的全部内容,更多相关mybatis内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(109)

评论列表共有 0 条评论

立即
投稿
返回
顶部