《锋迷商城》系列项目
链接: 《一》 项目搭建
链接: 《二》数据库的创建
链接: 《三》业务流程设计
文章目录
七、逆向工程配置
7.1 在mapper子工程下添加tkMapper的依赖
<!--tkmapper-->
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper-spring-boot-starter -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
修改api工程下的启动类 @MaperScan
7.2在mapper子工程下创建GeneralDAO 接口
创建genera包
创建GeneralDAO 接口
package com.sjtest.fmmall.general;
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
public interface GeneralDAO<T> extends Mapper<T>, MySqlMapper {
}
7.2在mapper子工程下添加 generator配置类 和在pom.xml下添加插件
7.2.1在resource 下添加 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>
<!--数据库链接地址账号密码-->
<context id="mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
<property name="beginningDelimiter" value=""/>
<property name="endingDelimiter" value=""/>
<!--配置GeneralDAO-->
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="com.sjtest.fmmall.general.GeneralDAO"/>
</plugin>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/fmmall?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&nullCatalogMeansCurrent=true"
userId="root"
password="8023zsj">
</jdbcConnection>
<javaTypeResolver>
<property name="forceBigDecimals" value="false"/>
</javaTypeResolver>
<!--生成实体类存放位置-->
<javaModelGenerator targetPackage="com.sjtest.fmmall.entity" targetProject="src/main/java"/>
<!--生成映射文件存放位置-->
<sqlMapGenerator targetPackage="/" targetProject="./src/main/resources/mappers"/>
<!--接口类-->
<javaClientGenerator type="XMLMAPPER" targetPackage="com.sjtest.fmmall.dao" targetProject="src/main/java"/>
<!--生成对应表及类名-->
<table tableName="%"></table>
</context>
</generatorConfiguration>
7.2.2pom.xml下添加插件
<build>
<plugins>
<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.5</version>
<configuration>
<!--配置文件的位置-->
<configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.1.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
7.3启动插件
### 问题- 生成的entity包在mapper子工程下里边的内容 需要手动移动到beans子工程的entity包下
- 移动后报错 是因为tkmapper 依赖没有移动 需要移动要beans子工程下