日期:2014-05-20  浏览次数:20712 次

spring aop记录日志
我想用spring记录日志:
我有一个数据表log  
id uname loginInDate loginOutDate
当用户登录进去的时候,会添加一条数据,记录用户的登录时间,当用户登出的时候,则需要更新log记录,把登出时间给记录。
求解释,我该怎么操作?
插入记录完全没有问题,关键就是怎么去做更新,
spring配置该怎么写?

------解决方案--------------------
XML code
<?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/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd 
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

    <!-- 配置接口UserServer -->
    <bean id="UserServer" class="com.feng.aop.UserServerImpl"></bean>
    <!-- 配置关注点 -->
    <bean id="SecurtyHandler" class="com.feng.aop.SecurtyHandler"></bean>
    <!-- AOP的配置 -->
    <aop:config>
        <!-- 切点的配置,当切点位于方面外时,此切点可以被所有的方面所共享 -->
        <aop:pointcut id="del"
        <!-- 切点表达式,用于配对连接点(方法)是否符合表达式的定义 -->
        <!-- 第一个*表示方法的返回值,del*表示配对以del开头的所有方法,最后..表示方法的参数可以为任意类型 -->
            expression="execution(*
            com.feng.aop.UserServerImpl.del*(..))" />
            <!-- 方面配置,一个方面用于处理相同类型的功能的模块 -->
            <aop:aspect id="allMethod" ref="SecurtyHandler">
                <aop:pointcut id="query"
                    expression="execution(* com.feng.aop.UserServerImpl.query*(..))" />
                    <!-- 通知的使用,当某个切点的表达式成立时,即调用此通知注入的方法 -->
                <aop:before method="check" pointcut-ref="query" />
                <aop:before method="check" pointcut-ref="del" />
            </aop:aspect>
    </aop:config>
</beans>

------解决方案--------------------
具体写法参考
http://blog.csdn.net/luohuijun619/article/details/4988679