设为首页 加入收藏

TOP

Spring AOP自定义注解方式实现日志管理(一)
2015-11-12 23:05:54 来源: 作者: 【 】 浏览:28
Tags:Spring AOP 定义 注解 方式 实现 日志 管理

今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理。废话不多说,直接开始!


关于配置我还是的再说一遍。


在applicationContext-mvc.xml中要添加的


? ?
? ?
? ? ? ?


? ?
? ?
? ?


? ?
? ?


? ?
? ?


接下来开始编写代码。


? ? 创建日志类实体


public class SystemLog {
? ? private String id;


? ? private String description;


? ? private String method;


? ? private Long logType;


? ? private String requestIp;


? ? private String exceptioncode;


? ? private String exceptionDetail;


? ? private String params;


? ? private String createBy;


? ? private Date createDate;


? ? public String getId() {
? ? ? ? return id;
? ? }


? ? public void setId(String id) {
? ? ? ? this.id = id == null ? null : id.trim();
? ? }


? ? public String getDescription() {
? ? ? ? return description;
? ? }


? ? public void setDescription(String description) {
? ? ? ? this.description = description == null ? null : description.trim();
? ? }


? ? public String getMethod() {
? ? ? ? return method;
? ? }


? ? public void setMethod(String method) {
? ? ? ? this.method = method == null ? null : method.trim();
? ? }


? ? public Long getLogType() {
? ? ? ? return logType;
? ? }


? ? public void setLogType(Long logType) {
? ? ? ? this.logType = logType;
? ? }


? ? public String getRequestIp() {
? ? ? ? return requestIp;
? ? }


? ? public void setRequestIp(String requestIp) {
? ? ? ? this.requestIp = requestIp == null ? null : requestIp.trim();
? ? }


? ? public String getExceptioncode() {
? ? ? ? return exceptioncode;
? ? }


? ? public void setExceptioncode(String exceptioncode) {
? ? ? ? this.exceptioncode = exceptioncode == null ? null : exceptioncode.trim();
? ? }


? ? public String getExceptionDetail() {
? ? ? ? return exceptionDetail;
? ? }


? ? public void setExceptionDetail(String exceptionDetail) {
? ? ? ? this.exceptionDetail = exceptionDetail == null ? null : exceptionDetail.trim();
? ? }


? ? public String getParams() {
? ? ? ? return params;
? ? }


? ? public void setParams(String params) {
? ? ? ? this.params = params == null ? null : params.trim();
? ? }


? ? public String getCreateBy() {
? ? ? ? return createBy;
? ? }


? ? public void setCreateBy(String createBy) {
? ? ? ? this.createBy = createBy == null ? null : createBy.trim();
? ? }


? ? public Date getCreateDate() {
? ? ? ? return createDate;
? ? }


? ? public void setCreateDate(Date createDate) {
? ? ? ? this.createDate = createDate;
? ? }
}


编写dao接口


package com.gcx.dao;


import com.gcx.entity.SystemLog;


public interface SystemLogMapper {
? ? int deleteByPrimaryKey(String id);


? ? int insert(SystemLog record);


? ? int insertSelective(SystemLog record);


? ? SystemLog selectByPrimaryKey(String id);


? ? int updateByPrimaryKeySelective(SystemLog record);


? ? int updateByPrimaryKey(SystemLog record);
}


编写service层


package com.gcx.service;


import com.gcx.entity.SystemLog;


public interface SystemLogService {


? ? int deleteSystemLog(String id);


? ? int insert(SystemLog record);
? ?
? ? int insertTest(SystemLog record);


? ? SystemLog selectSystemLog(String id);
? ?
? ? int updateSystemLog(SystemLog record);
}


编写service实现类serviceImpl


package com.gcx.service.impl;


import javax.annotation.Resource;


import org.springframework.stereotype.Service;


import com.gcx.annotation.Log;
import com.gcx.dao.SystemLogMapper;
import com.gcx.entity.SystemLog;
import com.gcx.service.SystemLogService;


@Service("systemLogService")
public class SystemLogServiceImpl implements SystemLogService {


? ? @Resource
? ? private SystemLogMapper systemLogMapper;
? ?
? ? @Override
? ? public int deleteSystemLog(String id) {
? ? ? ?
? ? ? ? return systemLogMapper.deleteByPrimaryKey(id);
? ? }


? ? @Override
? ?
? ? public int

首页 上一页 1 2 3 4 5 下一页 尾页 1/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Spring AOP的注解实例 下一篇Spring使用Cache

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: