IDEA 模板配置
一、tkMapper通用mapper配置
1 新建配置文件generatorConfig.xml,路径src/main/resources/generator/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>
<property name="endimgDelimiter" value=""></property>
<plugin type="tk.mybatis.mapper.generator.MapperPlugin">
<property name="mappers" value="com.itheima.general.GeneralDao"></property>
</plugin>
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://localhost:3306/tlias?useUnicode=true;characterEncoding=UTF-8;serverTimezone=Asia/Shangha"
userId="root"
password="123456">
</jdbcConnection>
<javaModelGenerator targetPackage="com.itheima.pojo" targetProject="src/main/java"/>
<sqlMapGenerator targetPackage="com.itheima.mapper" targetProject="src/main/resources"/>
<javaClientGenerator targetPackage="com.itheima.mapper" targetProject="src/main/java" type="XMLMAPPER"/>
<table tableName="operate_log">
<generatedKey column="id" sqlStatement="Mysql" identity="true"></generatedKey>
</table>
</context>
</generatorConfiguration>
3. 在工程pom文件添加通用Mapper依赖
<!-- tkMapper通用Mapper工具 -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
3. 在工程pom文件添加tkMapper自动代码生成工具
<!-- tkMapper自动代码生成工具 -->
<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>
</configuration>
<dependencies>
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.27</version>
</dependency>
<!--mapper-->
<!-- https://mvnrepository.com/artifact/tk.mybatis/mapper -->
<dependency>
<groupId>tk.mybatis</groupId>
<artifactId>mapper</artifactId>
<version>4.1.5</version>
</dependency>
</dependencies>
</plugin>
4. 新建Mapper通用继承接口GeneralDao,路径是src/main/java/com/itheima/general/GeneralDao.java,如下图所示:
import tk.mybatis.mapper.common.Mapper;
import tk.mybatis.mapper.common.MySqlMapper;
public interface GeneralDao<T> extends Mapper<T>, MySqlMapper<T> {
}
5 双击插件运行此插件,自动生成代码,如下图所示:
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/d0a61b5055de433a8ec66e55f9618516.png)
二、SpringBoot配置文件application.xml模板:
# 服务端口号
server:
port: 8080
# Spring配置
spring:
application:
# 服务名称
name: tlias-web-management
# 数据库配置
datasource:
#驱动类名称
driver-class-name: com.mysql.cj.jdbc.Driver
#数据库连接的url
url: jdbc:mysql://localhost:3306/tlias?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&failOverReadOnly=false&serverTimezone=Asia/Shanghai
#连接数据库的用户名
username: root
#连接数据库的密码
password: 123456
servlet:
multipart:
#配置单个文件上传大小限制
max-file-size: 10MB
#配置单个请求最大大小的限制 (一次请求中是可以上传多个文件)
max-request-size: 100MB
#配置mybatis的日志, 指定输出到控制台
mybatis:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#开启mybatis的驼峰命名自动映射开关 a_column ------> aCloumn
map-underscore-to-camel-case: true
# 自定义阿里云OSS配置信息
aliyun:
oss:
endpoint: https://oss-cn-guangzhou.aliyuncs.com
accessKeyId: LTAWYI5tKFYHhSeqEyXM1
accessKeySecret: sDdFaSAsdDeWYUrDSFDdETwiSOGTDdz3
bucketName: lsdlflsdnews
#spring事务管理日志
logging:
level:
org.springframework.jdbc.support.JdbcTransactionManager: debug
三、Mapper配置文件mybatis-mapper.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"https://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.itheima.mapper.EmpMapper">
</mapper>