大家好,又见面了,我是你们的朋友全栈君。
generator.properties:
spring.datasource.driverClassName=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://11.11.11.11:3306/travel?useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull&autoReconnect=true&failOverReadOnly=false&maxReconnects=10
spring.datasource.username=**
spring.datasource.password=***
targetJavaProject=src/main/java
targetResourcesProject=src/main/resources
#\u751F\u6210\u5B9E\u4F53\u7684\u5305\u540D\u548C\u4F4D\u7F6E
targetModelPackage=com.xyd.esign.server.dal.elasticsearch.model
#\u751F\u6210\u7684\u6620\u5C04\u6587\u4EF6\u5305\u540D\u548C\u4F4D\u7F6E
targetMapperPackage=mybatis.
#\u751F\u6210model\u7684\u5305\u540D\u548C\u4F4D\u7F6E
targetClientPackage=com.xyd.esign.server.dal.sign.dao
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>
<properties resource="generator.properties"/>
<!-- 数据库驱动包位置 -->
<!--<classPathEntry-->
<!--location="D:\程序\mysql-5.6.26-winx64\mysql-connector-java-5.1.17.jar" />-->
<context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<!-- TKmybatis配置 -->
<property name="javaFileEncoding" value="UTF-8"/>
<property name="beginningDelimiter" value="`"/>
<property name="endingDelimiter" value="`"/>
<plugin type="${mapper.plugin}">
<property name="mappers" value="${mapper.Mapper}"/>
</plugin>
<commentGenerator>
<!-- 是否去除自动生成的注释 true:是 : false:否 -->
<property name="suppressAllComments" value="true"/>
</commentGenerator>
<!-- 数据库链接URL、用户名、密码 -->
<jdbcConnection driverClass="${spring.datasource.driverClassName}" connectionURL="${spring.datasource.url}"
userId="${spring.datasource.username}" password="${spring.datasource.password}">
</jdbcConnection>
<!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="${targetModelPackage}" targetProject="${targetJavaProject}" />
<!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage="${targetMapperPackage}" targetProject="${targetResourcesProject}" />
<!-- 生成service的包名和位置 -->
<javaClientGenerator targetPackage="${targetClientPackage}" targetProject="${targetJavaProject}" type="XMLMAPPER" />
<!--<!– 要生成的那些表 –>-->
<table schema="" tableName="t_contract_config" domainObjectName="ContractConfig"
enableCountByExample="true" enableUpdateByExample="true"
enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true">
<generatedKey column="id" sqlStatement="MySql" identity="true"/>
</table>
</context>
</generatorConfiguration>
需要依赖:
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.20</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
idea双击运行如图:
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/126972.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...