1.引入Mysql
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-core</artifactId>
<version>1.3.6</version>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!-- 分页 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.6</version>
</dependency>
2.配置application.yml
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/ordershop
username: root
password: 123456
tomcat:
initial-size: 5
max-active: 30
aop:
auto: true
proxy-target-class: false
jpa:
hibernate:
ddl-auto: update
show-sql: true
mybatis:
mapperLocations: classpath:mybatis/mapper*.xml
typeAliasesPackage: com.lz.ordershop.*.model
pageHelper:
reasonable: "true"
supportMethodsArguments: "true"
returnPageInfo: check
params: count=countSql
3.配置一个数据库链接的配置文件 config.properties
# Mybatis Generator configuration
# MySQL Connector Jar
classPath=C:/Users/user/.m2/repository/mysql/mysql-connector-java/8.0.13/mysql-connector-java-8.0.13.jar
# MySQL
jdbc_driver=com.mysql.cj.jdbc.Driver
jdbc_url=jdbc:mysql://127.0.0.1:3306/ordershop?useUnicode=true&nullCatalogMeansCurrent=true
jdbc_user=root
jdbc_password=123456
4.配置自动生成的配置文件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="mybatis/config.properties"/>
<classPathEntry location="${classPath}"/>
<context id="context1" targetRuntime="MyBatis3">
<jdbcConnection driverClass="${jdbc_driver}" connectionURL="${jdbc_url}" userId="${jdbc_user}"
password="${jdbc_password}"/>
<javaModelGenerator targetPackage="com.lz.ordershop.sys.model" targetProject="src-gen\java"/>
<sqlMapGenerator targetPackage="com.lz.ordershop.sys.dao" targetProject="src-gen\resources"/>
<javaClientGenerator targetPackage="com.lz.ordershop.sys.dao" targetProject="src-gen\java"
type="ANNOTATEDMAPPER"/>
<table tableName="sys_authority"/>
<table tableName="sys_authority_copy"/>
</context>
</generatorConfiguration>
5.使用mavn命令进行生成
mvn antrun:run
mvn mybatis-generator:generate
网友评论