MySQL 使用触发器记录用户的操作日志问题

目录
  • MySQL 使用触发器记录用户的操作日志
  • 一、创建用户数据表(emp)和保存操作日志的表(emp_log)
  • 二、为 emp 表创建触发器
    • 1、创建触发器 trigger_after_insert_emp
    • 2、创建触发器 trigger_after_update_emp
    • 3、创建触发器 trigger_after_delete_emp
  • 三、数据验证
    • 1、在 emp 中添加数据记录
    • 2、在 emp 中更新数据记录
    • 3、在 emp 中删除数据记录

MySQL 使用触发器记录用户的操作日志

使用 MySQL 触发器可以记录哪些用户、什么时间对数据表进行了增、删、改操作。如果执行删除操作,则记录删除之前的数据记录;如果执行更新操作,记录更新之前的数据记录。

一、创建用户数据表(emp)和保存操作日志的表(emp_log)

-- 创建用户数据表:emp
DROP TABLE IF EXISTS  `emp`;
CREATE TABLE `emp` (
    `emp_id` int(11) AUTO_INCREMENT COMMENT '员工id',
    `emp_name` char(50) NOT NULL DEFAULT '' COMMENT '员工姓名',
    `birth` date COMMENT '出生日期',
    `salary` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '工资',
    `comm` decimal(10,2) NOT NULL DEFAULT 0.00 COMMENT '奖金',
    `phone` char(20) NOT NULL DEFAULT '' COMMENT '电话',
    `addr` varchar(200) NOT NULL DEFAULT '' COMMENT '地址',
    `created_at`  timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP comment '插入记录的时间',
    `updated_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '最后更新记录的时间',
    PRIMARY KEY (`emp_id`),
    KEY `idx_empname` (`emp_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '员工信息数据表';

-- 查看表结构
mysql> desc emp;
+------------+---------------+------+-----+-------------------+------------------------+
| Field      | Type          | Null | Key | Default           | Extra                  |
+------------+---------------+------+-----+-------------------+------------------------+
| emp_id     | int(11)       | NO   | PRI | NULL              | auto_increment         |
| emp_name   | char(50)      | NO   | MUL |                   |                        |
| birth      | date          | YES  |     | NULL              |                        |
| salary     | decimal(10,2) | NO   |     | 0.00              |                        |
| comm       | decimal(10,2) | NO   |     | 0.00              |                        |
| phone      | char(20)      | NO   |     |                   |                        |
| addr       | varchar(200)  | NO   |     |                   |                        |
| created_at | timestamp     | NO   |     | CURRENT_TIMESTAMP |                        |
| updated_at | timestamp     | NO   |    | CURRENT_TIMESTAMP | on update CURRENT_TIMESTAMP |
+------------+---------------+------+-----+-------------------+------------------------+
9 rows in set (0.00 sec)

-- 创建操作日志表:emp_log
DROP TABLE IF EXISTS  `emp_log`;
CREATE TABLE `emp_log` (
    `emplog_id` int(11) AUTO_INCREMENT COMMENT '操作日志id',
    `operate_type` char(20) COMMENT '操作类型:insert(插入)、delete(删除)、update(更新)',
    `operate_user` char(50) COMMENT '执行操作的用户名称',
    `operate_time` datetime COMMENT '操作时间',
    `emp_id` int(11) COMMENT '员工id',
    `emp_name` char(50) COMMENT '员工姓名',
    `birth` date COMMENT '出生日期',
    `salary` decimal(10,2) COMMENT '工资',
    `comm` decimal(10,2) COMMENT '奖金',
    `phone` char(20) COMMENT '电话',
    `addr` varchar(200) COMMENT '地址',
    PRIMARY KEY (`emplog_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT '员工操作日志信息表';

-- 查看表结构
mysql> desc emp_log;
+--------------+---------------+------+-----+---------+----------------+
| Field        | Type          | Null | Key | Default | Extra          |
+--------------+---------------+------+-----+---------+----------------+
| emplog_id    | int(11)       | NO   | PRI | NULL    | auto_increment |
| operate_type | char(20)      | YES  |     | NULL    |                |
| operate_user | char(50)      | YES  |     | NULL    |                |
| operate_time | datetime      | YES  |     | NULL    |                |
| emp_id       | int(11)       | YES  |     | NULL    |                |
| emp_name     | char(50)      | YES  |     | NULL    |                |
| birth        | date          | YES  |     | NULL    |                |
| salary       | decimal(10,2) | YES  |     | NULL    |                |
| comm         | decimal(10,2) | YES  |     | NULL    |                |
| phone        | char(20)      | YES  |     | NULL    |                |
| addr         | varchar(200)  | YES  |     | NULL    |                |
+--------------+---------------+------+-----+---------+----------------+
11 rows in set (0.01 sec)

二、为 emp 表创建触发器

1、创建触发器 trigger_after_insert_emp

在 emp 表中插入记录时,把执行插入操作的用户名、操作类型(INSERT)、操作时间以及记录的内容添加到操作日志表(emp_log)中。

DROP TRIGGER IF EXISTS `trigger_after_insert_emp`;

delimiter //
create trigger trigger_after_insert_emp
after insert on emp
for each row
begin
insert into emp_log(
    operate_type,
    operate_user,
    operate_time,
    emp_id,
    emp_name,
    birth,
    salary,
    comm,
    phone,
    addr
)
values(
    'INSERT',
    user(),
    now(),
    new.emp_id,
    new.emp_name,
    new.birth,
    new.salary,
    new.comm,
    new.phone,
    new.addr
);
end //
delimiter ;

2、创建触发器 trigger_after_update_emp

在 emp 表中更新记录时,把执行更新操作的用户名、操作类型(UPDATE)、操作时间以及更新之前记录的内容添加到操作日志表(emp_log)中。

DROP TRIGGER IF EXISTS `trigger_after_update_emp`;

delimiter //
create trigger trigger_after_update_emp
after update on emp
for each row
begin
insert into emp_log(
    operate_type,
    operate_user,
    operate_time,
    emp_id,
    emp_name,
    birth,
    salary,
    comm,
    phone,
    addr
)
values(
    'UPDATE',
    user(),
    now(),
    old.emp_id,
    old.emp_name,
    old.birth,
    old.salary,
    old.comm,
    old.phone,
    old.addr
);
end //
delimiter ;

3、创建触发器 trigger_after_delete_emp

在 emp 表中删除记录时,把执行删除操作的用户名、操作类型(DELETE)、操作时间以及删除之前记录的内容添加到操作日志表(emp_log)中。

DROP TRIGGER IF EXISTS `trigger_after_delete_emp`;

delimiter //
create trigger trigger_after_delete_emp
after delete on emp
for each row
begin
insert into emp_log(
    operate_type,
    operate_user,
    operate_time,
    emp_id,
    emp_name,
    birth,
    salary,
    comm,
    phone,
    addr
)
values(
    'DELETE',
    user(),
    now(),
    old.emp_id,
    old.emp_name,
    old.birth,
    old.salary,
    old.comm,
    old.phone,
    old.addr
);
end //
delimiter ;

三、数据验证

1、在 emp 中添加数据记录

/*
insert into emp(emp_name,birth,salary,comm,phone,addr)
values('刘红','1988-12-3',5000,1200,'13673521212','河南省新乡市'),
('王涛','1984-8-21',6000,700,'13755440012','河南省郑州市'),
('张静','1992-10-31',5500,800,'13073526644','河南省安阳市');
*/
mysql> insert into emp(emp_name,birth,salary,comm,phone,addr)
    -> values('刘红','1988-12-3',5000,1200,'13673521212','河南省新乡市'),
    -> ('王涛','1984-8-21',6000,700,'13755440012','河南省郑州市'),
    -> ('张静','1992-10-31',5500,800,'13073526644','河南省安阳市');
Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0

-- 查询 emp 表中的数据
mysql> select * from emp;
+--------+----------+------------+---------+---------+-------------+--------------------+---------------------+---------------------+
| emp_id | emp_name | birth      | salary  | comm    | phone       | addr               | created_at          | updated_at          |
+--------+----------+------------+---------+---------+-------------+--------------------+---------------------+---------------------+
|      1 | 刘红     | 1988-12-03 | 5000.00 | 1200.00 | 13673521212 | 河南省新乡市       | 2022-12-04 15:40:08 | 2022-12-04 15:40:08 |
|      2 | 王涛     | 1984-08-21 | 6000.00 |  700.00 | 13755440012 | 河南省郑州市       | 2022-12-04 15:40:08 | 2022-12-04 15:40:08 |
|      3 | 张静     | 1992-10-31 | 5500.00 |  800.00 | 13073526644 | 河南省安阳市       | 2022-12-04 15:40:08 | 2022-12-04 15:40:08 |
+--------+----------+------------+---------+---------+-------------+--------------------+---------------------+---------------------+
3 rows in set (0.00 sec)

-- 查询 emp_log 表中的数据
mysql> select * from emp_log;
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
| emplog_id | operate_type | operate_user   | operate_time        | emp_id | emp_name | birth      | salary  | comm    | phone       | addr               |
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
|         1 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      1 | 刘红     | 1988-12-03 | 5000.00 | 1200.00 | 13673521212 | 河南省新乡市       |
|         2 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      2 | 王涛     | 1984-08-21 | 6000.00 |  700.00 | 13755440012 | 河南省郑州市       |
|         3 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      3 | 张静     | 1992-10-31 | 5500.00 |  800.00 | 13073526644 | 河南省安阳市       |
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
3 rows in set (0.01 sec)

2、在 emp 中更新数据记录

-- 更新 emp 表中的数据(更新了两条记录)
mysql> update emp set salary = salary + 1000 where salary < 6000;
Query OK, 2 rows affected (0.01 sec)
Rows matched: 2  Changed: 2  Warnings: 0

-- 查询 emp 表中的数据
mysql> select * from emp;
+--------+----------+------------+---------+---------+-------------+--------------------+---------------------+---------------------+
| emp_id | emp_name | birth      | salary  | comm    | phone       | addr               | created_at          | updated_at          |
+--------+----------+------------+---------+---------+-------------+--------------------+---------------------+---------------------+
|      1 | 刘红     | 1988-12-03 | 6000.00 | 1200.00 | 13673521212 | 河南省新乡市       | 2022-12-04 15:40:08 | 2022-12-04 15:47:56 |
|      2 | 王涛     | 1984-08-21 | 6000.00 |  700.00 | 13755440012 | 河南省郑州市       | 2022-12-04 15:40:08 | 2022-12-04 15:40:08 |
|      3 | 张静     | 1992-10-31 | 6500.00 |  800.00 | 13073526644 | 河南省安阳市       | 2022-12-04 15:40:08 | 2022-12-04 15:47:56 |
+--------+----------+------------+---------+---------+-------------+--------------------+---------------------+---------------------+
3 rows in set (0.00 sec)

-- 查询 emp_log 表中的数据
mysql> select * from emp_log;
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
| emplog_id | operate_type | operate_user   | operate_time        | emp_id | emp_name | birth      | salary  | comm    | phone       | addr               |
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
|         1 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      1 | 刘红     | 1988-12-03 | 5000.00 | 1200.00 | 13673521212 | 河南省新乡市       |
|         2 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      2 | 王涛     | 1984-08-21 | 6000.00 |  700.00 | 13755440012 | 河南省郑州市       |
|         3 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      3 | 张静     | 1992-10-31 | 5500.00 |  800.00 | 13073526644 | 河南省安阳市       |
|         4 | UPDATE       | root@localhost | 2022-12-04 15:47:56 |      1 | 刘红     | 1988-12-03 | 5000.00 | 1200.00 | 13673521212 | 河南省新乡市       |
|         5 | UPDATE       | root@localhost | 2022-12-04 15:47:56 |      3 | 张静     | 1992-10-31 | 5500.00 |  800.00 | 13073526644 | 河南省安阳市       |
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
5 rows in set (0.01 sec)

3、在 emp 中删除数据记录

-- 删除 emp 表中的数据(删除了两条记录)
mysql> delete from emp where salary = 6000;
Query OK, 2 rows affected (0.02 sec)

-- 查询 emp 表中的数据
mysql> select * from emp;
+--------+----------+------------+---------+--------+-------------+--------------------+---------------------+---------------------+
| emp_id | emp_name | birth      | salary  | comm   | phone       | addr               | created_at          | updated_at          |
+--------+----------+------------+---------+--------+-------------+--------------------+---------------------+---------------------+
|      3 | 张静     | 1992-10-31 | 6500.00 | 800.00 | 13073526644 | 河南省安阳市       | 2022-12-04 15:40:08 | 2022-12-04 15:47:56 |
+--------+----------+------------+---------+--------+-------------+--------------------+---------------------+---------------------+
1 row in set (0.00 sec)

-- 查询 emp_log 表中的数据
mysql> select * from emp_log;
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
| emplog_id | operate_type | operate_user   | operate_time        | emp_id | emp_name | birth      | salary  | comm    | phone       | addr               |
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
|         1 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      1 | 刘红     | 1988-12-03 | 5000.00 | 1200.00 | 13673521212 | 河南省新乡市       |
|         2 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      2 | 王涛     | 1984-08-21 | 6000.00 |  700.00 | 13755440012 | 河南省郑州市       |
|         3 | INSERT       | root@localhost | 2022-12-04 15:40:08 |      3 | 张静     | 1992-10-31 | 5500.00 |  800.00 | 13073526644 | 河南省安阳市       |
|         4 | UPDATE       | root@localhost | 2022-12-04 15:47:56 |      1 | 刘红     | 1988-12-03 | 5000.00 | 1200.00 | 13673521212 | 河南省新乡市       |
|         5 | UPDATE       | root@localhost | 2022-12-04 15:47:56 |      3 | 张静     | 1992-10-31 | 5500.00 |  800.00 | 13073526644 | 河南省安阳市       |
|         6 | DELETE       | root@localhost | 2022-12-04 15:52:21 |      1 | 刘红     | 1988-12-03 | 6000.00 | 1200.00 | 13673521212 | 河南省新乡市       |
|         7 | DELETE       | root@localhost | 2022-12-04 15:52:21 |      2 | 王涛     | 1984-08-21 | 6000.00 |  700.00 | 13755440012 | 河南省郑州市       |
+-----------+--------------+----------------+---------------------+--------+----------+------------+---------+---------+-------------+--------------------+
7 rows in set (0.00 sec)

到此这篇关于MySQL 使用触发器记录用户的操作日志的文章就介绍到这了,更多相关mysql记录用户的操作日志内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

(0)

相关推荐

  • MySQL如何创建触发器

    本文实例为大家分享了MySQL创建触发器的具体代码,供大家参考,具体内容如下 先来个实例: #建表 DROP TABLE IF EXISTS t_attendance; CREATE TABLE t_attendance ( job_no VARCHAR(30) DEFAULT '', operateTime VARCHAR(20) DEFAULT '', INDEX index_operateTime(operateTime), INDEX index_jobNo(job_no) ) ENGI

  • MySQL触发器简单用法示例

    本文实例讲述了MySQL触发器简单用法.分享给大家供大家参考,具体如下: mysql触发器和存储过程一样,是嵌入到mysql的一段程序,触发器是由事件来触发的,这些事件包括,INSERT,UPDATE,DELETE,不包括SELECT 创建触发器 CREATE TRIGGER name,time,event ON table_name FOR EACH ROW trigger_stmt 例如 复制代码 代码如下: CREATE TRIGGER ins_sum BEFORE INSERT ON a

  • Mysql中禁用与启动触发器教程【推荐】

    在使用MYSQL过程中,经常会使用到触发器,但是有时使用不当会造成一些麻烦.有没有一种办法可以控制触发器的调用呢? 触发器顾名思义就是数据库在一定的调条件自动调用的SQL语句,触发器拒绝了人工调用的过程,由数据库MYSQL数据库自动的调用,执行更加高效. 如何禁用触发器呢? 1.新建两张表: 表demo_1: CREATE TABLE `demo_1` ( `ID` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键', `STUNAME` varchar(3

  • mysql 触发器用法实例详解

     MySQL触发器语法详解: 触发器 trigger是一种特殊的存储过程,他在插入(inset).删除(delete)或修改(update)特定表中的数据时触发执行,它比数据本身标准的功能更精细和更复杂的数据控制能力.触发器不是由程序调用,而是由某个事件来触发的.在有数据修改时自动强制执行其业务规则,经常用于加强数据的完整性约束和业务规则等.触发器可以查询其他表,而且包含复制的sql语句.触发器也可用于强制引用完整性.触发器可以强制比用check约束定义的约束更为复杂的约束. (一).CREAT

  • mysql触发器之触发器的增删改查操作示例

    本文实例讲述了mysql触发器之触发器的增删改查操作.分享给大家供大家参考,具体如下: 我们在创建触发器后,可以在包含触发器定义文件的数据文件夹中显示其定义.触发器作为纯文本文件存储在以下数据库文件夹中: /data_folder/database_name/table_name.trg 我们还可通过查询information_schema数据库中的triggers表来显示触发器,如下所示: SELECT * FROM information_schema.triggers WHERE trig

  • MySQL触发器概念、原理与用法详解

    本文实例讲述了MySQL触发器概念.原理与用法.分享给大家供大家参考,具体如下: 1.触发器的概念 触发器(trigger)是MySQL提供给程序员和数据分析员来保证数据完整性的一种方法,它是与表事件相关的特殊的存储过程,它的执行不是由程序调用,也不是手工启动,而是由事件来触发,比如当对一个表进行操作(insert,delete, update)时就会激活它执行.--百度百科 上面是百度给的触发器的概念,我理解的触发器的概念,就是你执行一条sql语句,这条sql语句的执行会自动去触发执行其他的s

  • mysql日志触发器实现代码

    sql语句 DROP TRIGGER IF EXISTS sys_menu_edit; CREATE TRIGGER sys_menu_edit BEFORE UPDATE ON sys_menu FOR EACH ROW BEGIN INSERT INTO `g4m`.`sys_log` ( `table_name`, `val_id`, `data_json` ) VALUES ( 'sys_menu', old.id, CONCAT( "{", CONCAT_WS( ',', C

  • MySQL 使用触发器记录用户的操作日志问题

    目录 MySQL 使用触发器记录用户的操作日志 一.创建用户数据表(emp)和保存操作日志的表(emp_log) 二.为 emp 表创建触发器 1.创建触发器 trigger_after_insert_emp 2.创建触发器 trigger_after_update_emp 3.创建触发器 trigger_after_delete_emp 三.数据验证 1.在 emp 中添加数据记录 2.在 emp 中更新数据记录 3.在 emp 中删除数据记录 MySQL 使用触发器记录用户的操作日志 使用

  • 一文带你了解MySQL中触发器的操作

    目录 概述 介绍 触发器的特性 操作—创建触发器 操作—new和old 操作—查看触发器 操作—删除触发器 注意事项 概述 介绍 触发器,就是一种特殊的存储过程.触发器和存储过程一样是一个能够完成特定功能.存储在数据库服务器上的SQL片段,但是触发器无需调用,当对数据库表中的数据执行DML操作时自动触发这个SQL片段的执行,无需手动条用. 在MySQL中,只有执行insert,delete,update操作时才能触发触发器的执行 触发器的这种特性可以协助应用在数据库端确保数据的完整性,日志记录,

  • SpringBoot使用AOP记录接口操作日志的方法

    目录 一.操作日志简介 1.1.系统日志和操作日志的区别 1.2.操作日志记录实现方式 二.AOP面向切面编程 2.1.AOP简介 2.2.AOP作用 2.3.AOP相关术语 2.4.JointPoint和ProceedingJoinPoint 2.5.AOP相关注解 三.AOP切面实现接口日志记录 3.1.引入AOP依赖 3.2.创建日志信息封装类WebLog 3.3.创建切面类WebLogAspect 3.4.调用接口进行测试 四.AOP切面+自定义注解实现接口日志记录 4.1.自定义日志注

  • JSP 自定义注解及记录操作日志

    JSP 自定义注解及记录操作日志 Spring的配置文件 <aop:aspectj-autoproxy /> 日志拦截器 package com.vem.interceptor; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.anno

  • SpringBoot使用AOP记录接口操作日志详解

    SpringBoot 使用 AOP 记录接口操作日志,供大家参考,具体内容如下 一.AOP简介 1.什么是AOP AOP:Aspect Oriented Programming 面向切面编程 AOP关注不是某一个类或某些方法:控制大量资源,关注的是大量的类和方法. 2.AOP应用场景以及常用术语 权限控制.缓存控制.事务控制.分布式追踪.异常处理等 Target:目标类,即需要被代理的类.例如:UserService Joinpoint(连接点):所谓连接点是指那些可能被拦截到的方法.例如:所有

  • springAop实现权限管理数据校验操作日志的场景分析

    前言 作为一个写java的使用最多的轻量级框架莫过于spring,不管是老项目用到的springmvc,还是现在流行的springboot,都离不开spring的一些操作,我在面试的时候问的最多的spring的问题就是我们在平常的项目中使用spring最多的有哪几个点 在我看来无非就两个 spring的bean管理,说的高大上一点就是spring的ioc,di spring的AOP spring是一个很强大的轻量级框架,功能远不止这两点,但是我们用的最多的就是这两点. spring bean 管

  • 利用spring AOP记录用户操作日志的方法示例

    前言 最近项目已经开发完成,但发现需要加用户操作日志,如果返回去加也不太现实,所以使用springAOP来完成比较合适.下面来一起看看详细的介绍: 注解工具类: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface LogAnnotation { String operateModelNm() default ""; String operateFuncNm() default

  • Laravel框架实现利用中间件进行操作日志记录功能

    本文实例讲述了Laravel框架实现利用中间件进行操作日志记录功能.分享给大家供大家参考,具体如下: 利用中间件进行操作日志记录过程: 1.创建中间件 php artisan make:middleware AdminOperationLog 2.生成了文件./app/Http/Middleware/AdminOperationLog.php 代码如下: <?php namespace App\Http\Middleware; use Closure; use Illuminate\Http\R

  • Spring Cloud Gateway 记录请求应答数据日志操作

    我就废话不多说了,大家还是直接看代码吧~ public class GatewayContext { public static final String CACHE_GATEWAY_CONTEXT = "cacheGatewayContext"; /** * cache json body */ private String cacheBody; /** * cache formdata */ private MultiValueMap<String, String> f

  • 使用SpringBoot AOP 记录操作日志、异常日志的过程

    平时我们在做项目时经常需要对一些重要功能操作记录日志,方便以后跟踪是谁在操作此功能:我们在操作某些功能时也有可能会发生异常,但是每次发生异常要定位原因我们都要到服务器去查询日志才能找到,而且也不能对发生的异常进行统计,从而改进我们的项目,要是能做个功能专门来记录操作日志和异常日志那就好了, 当然我们肯定有方法来做这件事情,而且也不会很难,我们可以在需要的方法中增加记录日志的代码,和在每个方法中增加记录异常的代码,最终把记录的日志存到数据库中.听起来好像很容易,但是我们做起来会发现,做这项工作很繁

随机推荐