在Spring框架中,使用AOP配合自定义注解可以方便的实现用户操作的监控。首先搭建一个基本的Spring Boot Web环境开启Spring Boot,然后引入必要依赖:
依赖文件
<!-- aop依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
<!--hutool工具包-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.3.10</version>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.45</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.8</version>
</dependency>
<!--lombok插件-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
配置文件
server:
port: 9910
session:
timeout: 600000
spring:
application:
name: security
datasource:
url: jdbc:mysql://127.0.0.1:3306/gmrb?useSSL=false&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&zeroDateTimeBehavior=convertToNull
username: root
password: 123456
type: com.alibaba.druid.pool.DruidDataSource
driver-class-name: com.mysql.jdbc.Driver
initialSize: 5
minIdle: 5
maxActive: 20
maxWait: 60000
tomcat:
min-evictable-idle-time-millis: 300000
test-while-idle: true
mybatis:
config-location: classpath:mybatis/mybatis-config.xml
mapper-locations: classpath:mappers/*.xml
mysql日志分为两种,第一种用于运维,这一种日志需要打印的信息比较多比较全,通常打印在控制台,然后持久化到磁盘或者同步到第三方数据系统中;第二种用于记录用户操作,便于管理员查看,通常记录在数据库,并在平台上展示。
本文讨论的是第二种情况。
数据库文件
创建数据库文件,生成对应的实体:
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for t_admin_log
-- ----------------------------
DROP TABLE

最低0.47元/天 解锁文章
4395





