本文来说下mybatis-config常用的实例
程序搭建
搭建一个springboot单体服务
maven导入
<!--mysql-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>
yaml文件
# 应用服务 WEB 访问端口
server:
port: 9988
spring:
datasource:
url: jdbc:mysql://localhost:3306/product?serverTimezone=UTC&useSSL
=false&useUnicode=true&characterEncoding=UTF-8
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
mybatis:
config-location: classpath:mybatis/mybatis-config.xml
mapper-locations: classpath:mybatis/mapper/*.xml
使用实例
config配置
config配置
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<!-- 驼峰 -->
<setting name="mapUnderscoreToCamelCase" value="true" />
<!-- 打印sql日志 -->
<setting name="logImpl" value="STDOUT_LOGGING" />
</settings>
</configuration>
驼峰使用
mapper
实体
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Order {
private Long id;
private String addressInfo;
private String remark;
}
数据库数据
程序测试
日志打印
打印sql日志信息
总结
本文说了mybatis-config使用常用的几个实例