项目整理三-Spring AOP实现日志管理

applicationContextAop.xml
<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
       xmlns:aop="http://www.springframework.org/schema/aop"  
       xsi:schemaLocation="  
       http://www.springframework.org/schema/beans   
       http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  
       http://www.springframework.org/schema/aop   
       http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">  

       <bean id="customerDeviceService" class="com.hdst.service.impl.CustomerDeviceVService_Impl"></bean>
       <bean id="alarmInfoTService" class="com.hdst.service.impl.AlarmInfoTService_Impl"></bean>
       <bean id="alarmSettingInfoTService" class="com.hdst.service.impl.AlarmSettingInfoTService_Impl"></bean>
       <bean id="scriptInfoTService" class="com.hdst.service.impl.ScriptInfoTService_Impl"></bean>
       <bean id="areaManageService" class="com.hdst.service.impl.AreaManageService_Impl"></bean>
       <bean id="customerInfoManageService" class="com.hdst.service.impl.CustomerInfoManageService_Impl"></bean>
       <bean id="deviceManageService" class="com.hdst.service.impl.DeviceManageService_Impl"></bean>
       <bean id="measurePointRelationService" class="com.hdst.service.impl.MeasurePointRelationService_Impl"></bean>

       <bean id="logAdvice" class="com.hdst.aop.SystemLogAdvice"/>  
       <aop:config>
           <aop:aspect id="logAspect" ref="logAdvice">  
                <aop:pointcut id="anyMethod" expression="@annotation(com.hdst.annotation.MethodDescriptionAnnotation)" />  
                <aop:before method="generateLog" pointcut-ref="anyMethod" />  
           </aop:aspect> 
       </aop:config>

</beans>  
SystemLogAdvice.java
public class SystemLogAdvice {
    private void generateLog(JoinPoint joinPoint){
        MethodSignature ms=(MethodSignature) joinPoint.getSignature();
        Method method=ms.getMethod();
        Object[] args = joinPoint.getArgs();
        String operationArgs = "";
        for(int i=0;i<args.length;i++){
            operationArgs+=args[0].toString()+";";
        }
        String adminUserName = Constant.adminUser.getUsername();
        String operationDescription = method.getAnnotation(MethodDescriptionAnnotation.class).methodDescription();
        String sql = "insert into device_log_info_t_"+((new Date()).getYear()+1900)+((new Date()).getMonth()+1)+" values("+
        "null,'"+adminUserName+"',now()"+",'"+operationDescription+"','"+operationArgs+"')";
        HibernateUtil.executeSQLUpdate(sql, null);
        System.out.println(sql);
    }
}
MethodDescriptionAnnotation.java
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD })
public @interface MethodDescriptionAnnotation {
    String methodDescription();
}

这里使用的是jdk代理,拦截在service上

public interface DeviceManageService_Intf {
    ......
    @MethodDescriptionAnnotation(methodDescription = "新增设备")
    int insertDevice(String areaId,DeviceInfoT deviceInfoT,String openVolume,String type,String oldId);

    @MethodDescriptionAnnotation(methodDescription = "修改设备信息")
    int updateDevice(MeasurementPointDeviceInfoV measurementPointDeviceInfoV);
    int getCount(String adminId,String search_text);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本方法。编译原理不仅是计算机科学理论的重要组成部分,也是实现高效、可靠的计算机程序设计的关键。本文将对编译原理的基本概念、发展历程、主要内容和实际应用进行详细介绍编译原理是计算机专业的一门核心课程,旨在介绍编译程序构造的一般原理和基本

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值