我是靠谱客的博主 霸气煎饼,这篇文章主要介绍SpringBoot之mybatis-generator自动生成SpringBoot之mybatis-generator自动生成,现在分享给大家,希望可以做个参考。

SpringBoot之mybatis-generator自动生成

上文说道勤快的人已经可以开始使用spring boot+mybatis了,这次就来说说懒得人怎么用:

mybatis-generator用过的人都知道,俩字方便,一次配置,到处使用下面就说下spring boot里边怎么配置,pom.xml里加入如下插件

复制代码
1
2
3
4
5
6
7
8
9
<plugin> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-maven-plugin</artifactId> <version>1.3.2</version> <configuration> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> </plugin>

resource目录下创建generatorConfig.xml文件

复制代码
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
<?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> <properties resource="application.yml" /> <!-- mysql驱动的位置 --> <classPathEntry location="C:Usersadmin.m2repositorymysqlmysql-connector-java5.1.38mysql-connector-java-5.1.38.jar" /> <context id="Tables" targetRuntime="MyBatis3"> <!-- 注释 --> <commentGenerator> <!-- 是否生成注释代时间戳 --> <property name="suppressDate" value="true"/> <!-- 是否去除自动生成的注释 true:是 : false:否 --> <property name="suppressAllComments" value="true"/> </commentGenerator> <!-- JDBC连接 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/dbzb" userId="root" password="tiger"> </jdbcConnection> <!-- 非必需,类型处理器,在数据库类型和java类型之间的转换控制--> <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal --> <javaTypeResolver> <!-- 是否使用bigDecimal, false可自动转化以下类型(Long, Integer, Short, etc.) --> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成实体类地址 --> <javaModelGenerator targetPackage="com.shx.dao.model" targetProject="src/main/java"> <!-- 从数据库返回的值被清理前后的空格 --> <property name="trimStrings" value="true" /> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </javaModelGenerator> <!-- 生成mapper xml文件 --> <sqlMapGenerator targetPackage="com.shx.dao.mapper" targetProject="src/main/java"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </sqlMapGenerator> <!-- 生成mapper xml对应Client--> <javaClientGenerator targetPackage="com.shx.dao.mapper" targetProject="src/main/java" type="XMLMAPPER"> <!-- enableSubPackages:是否让schema作为包的后缀 --> <property name="enableSubPackages" value="false" /> </javaClientGenerator> <!-- 配置表信息 --> <!-- schema即为数据库名 tableName为对应的数据库表 domainObjectName是要生成的实体类 enable*ByExample 是否生成 example类 --> <table schema="t_livetype" tableName="t_livetype" domainObjectName="LiveType" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"> </table> </context> </generatorConfiguration>

OK,到此为止大功告成,ide右侧maven窗口右键run一下就可以了,success之后你需要的model,mapper就都有了,然后把上文提到的application处@MapperScan(basePackages = “com.shx.dao”)和application.yml的
type-aliases-package: classpath*:com.shx.dao.model
mapper-locations: classpath*:com.shx.dao.mapper/*.xml
改成你自己的包路径就可以了

这里写图片描述

最后

以上就是霸气煎饼最近收集整理的关于SpringBoot之mybatis-generator自动生成SpringBoot之mybatis-generator自动生成的全部内容,更多相关SpringBoot之mybatis-generator自动生成SpringBoot之mybatis-generator自动生成内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部