Spring AOP切面实现系统操作日志
自定义注解,放置的目标位置
import java.lang.annotation.*;
@Target(ElementType.METHOD) //注解放置的目标位置,METHOD是可注解在方法级别上
@Retention(RetentionPolicy.RUNTIME) //注解在哪个阶段执行
@Documented
public @interface SysLog {
String operContent() default ""; // 内容
String moduleName() default ""; // 模块名称
String operType() default ""; // 操作类型(登录,增加,删除,修改,查询,查看...)
}
系统操作日志对象
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
import java.time.LocalDateTime;
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("sys_operation_log")
@ApiModel(value="Log对象", description="系统操作日志")
public class SysOperationLog implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty("设备ID")
@TableId(value = "id", type = IdType.ASSIGN_ID)
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
@ApiModelProperty(value = "模块名称")
@TableField("module_name")
private String moduleName;
@ApiModelProperty(value = "操作人ID")
@TableField("user_id")
private String userId;
@ApiModelProperty(value = "操作类型")
@TableField("oper_type")
private String operType;
@ApiModelProperty(value = "操作名称")
@TableField("user_name")
private String userName;
@ApiModelProperty(value = "操作账号")
@TableField("user_account")
private String userAccount;
@ApiModelProperty(value = "操作时间")
@TableField("oper_time")
private LocalDateTime operTime;
@ApiModelProperty(value = "操作内容")
@TableField("oper_content")
private String operContent;
@ApiModelProperty(value = "ip")
@TableField(