如何让你的springBoot项⽬项⽬打印MyBatis的操作sql语句以
及操作参数?(⼊。。。
1.为什么我们需要打印操作数据的sql语句?
答:不打印操作数据库sql语句的项⽬,简直就是维护⼈员的噩梦,调试难度及其困难,如果是⼆⼿代码,简直真的是祖传代码是屎⼭,我前⼏天维护别⼈的屎⼭代码,然后啥⽇志不打印,把我搞得⼼态爆炸。所以我决定把这个问题解决!
2.⽬录结构:
2.pom⽂件这样写
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="/POM/4.0.0" xmlns:xsi="/2001/XMLSchema-instance"
xsi:schemaLocation="/POM/4.0.0 /xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId&le</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<description>Demo project for Spring Boot</description>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>            <optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j</artifactId>
<version>1.3.8.RELEASE</version>
</dependency>
<!--mybatis-->
<dependency>
<groupId&batis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.2</version>
<!-- 请不要使⽤1.0.0版本,因为还不⽀持插件 -->
</dependency>
<!-- alibaba druid-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependency>
<!-- MySql数据库驱动 -->
<dependency>
<groupId> mysql</groupId>
<artifactId> mysql-connector-java</artifactId>
<version> 5.1.46</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>                <artifactId>spring-boot-maven-plugin</artifactId>            </plugin>
</plugins>
</build>
</project>
l配置⽂件这样写
spring:
#  profiles:
#    active: dev
datasource:
druid:
min-idle: 1
max-pool-prepared-statement-per-connection-size: 20
test-while-idle: true
time-between-eviction-runs-millis: 60000
max-active: 20
validation-query: SELECT 'x'
filters: stat
max-wait: 60000
url: jdbc:mysql://172.21.13.212:3306/zlb?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true      test-on-borrow: false
password: coship
pool-prepared-statements: false
initial-size: 1
min-evictable-idle-time-millis: 300000
driver-class-name: sql.jdbc.Driver
username: root
test-on-return: false
name: zlb
#  type: com.alibaba.druid.pool.DruidDataSource
mybatis:
mapper-locations: classpath:mapper/*.xml
config-location: classpath:l
type-aliases-package: del
#mybatis:
#  configuration:
#    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
#整合mybatis 显⽰打印sql以及参数(最重要)
logging:
level:
5.java类这样写
(1)controller
ller;
del.User;
ample.demo.service.serviceImpl.UserServiceImpl;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("zlb")
public class UserController {
@Autowired
private UserServiceImpl userService;
private Logger logger = Logger(UserController.class);
@GetMapping("/userInfo")
public User getUserInfo(){
UserInfo();
}
}
(2)service
ample.demo.service;
del.User;
public interface UserService {
User getUserInfo();
}
springboot结构ample.demo.service.serviceImpl;
ample.demo.dao.UserDao;
del.User;
ample.demo.service.UserService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class UserServiceImpl implements UserService {
private static final Logger logger = Logger(UserServiceImpl.class);    @Autowired
private UserDao userDao;
@Override
public User getUserInfo() {
UserInfo();
}
}
(3)dao

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。