千峰商城-springboot项目搭建-16-整合tkMapper
1.在fmmall项目的mapper子工程的pom中添加依赖: <dependency><groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency> 2.在api子工程的ApiApplication中更改@MapperScan的important:import tk.mybatis.spring.annotation.MapperScan;
package com.qfedu.fmmall;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import tk.mybatis.spring.annotation.MapperScan;
@SpringBootApplication
@MapperScan("com.qfedu.fmmall.dao")
public class ApiApplication {
public static void main(String[] args) {
SpringApplication.run(ApiApplication.class, args);
}
}
3.删除beans中的所有entity,mapper中的所有dao和mapper.xml。
4.在mapper子工程的pom文件中添加tkmapper插件和依赖。
<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/generator/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.28</version>
</dependency>
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.1.5</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>5.在mapper子工程中添加配置:
https://img2022.cnblogs.com/blog/2619721/202206/2619721-20220624005535897-24668261.png
<?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="`"/>
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="com.qfedu.fmmall.general.GeneralDAO"/>
</plugin>
<jdbcConnection driverClass="com.mysql.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/fmmall2?useSSL=false"
userId="root" password="123456">
<property name="nullCatalogMeansCurrent" value="true"/>
</jdbcConnection>
<javaModelGenerator targetPackage="com.qfedu.fmmall.entity" targetProject="src/main/java"/>
<sqlMapGenerator targetPackage="/" targetProject="src/main/resources/mappers"/>
<javaClientGenerator targetPackage="com.qfedu.fmmall.dao" targetProject="src/main/java" type="XMLMAPPER"/>
<table tableName="%"></table>
</context>
</generatorConfiguration>6.添加插件的configuration。
<configuration>
<configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
<verbose>true</verbose>
<overwrite>true</overwrite>
</configuration>7.双击maven中的generator:generate。
https://img2022.cnblogs.com/blog/2619721/202206/2619721-20220624010409141-516820517.png
生成成功!
https://img2022.cnblogs.com/blog/2619721/202206/2619721-20220624010506870-787861351.png
8.将生成的所有entity移到beans子工程下的entity包中。
https://img2022.cnblogs.com/blog/2619721/202206/2619721-20220624010732663-1137422004.png
9.将原本在mapper子工程的pom中的tkmapper依赖转移到beans子工程中。刷新maven包。
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
10.在http://localhost:8080/doc.html中进行接口测试。https://img2022.cnblogs.com/blog/2619721/202206/2619721-20220624023536856-1348287480.png
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
页:
[1]