zoukankan      html  css  js  c++  java
  • spring mvc+jpa CreatedDate Auditing 增加审计功能

    jpa支持审计功能都是熟知的,但网上都是spring boot的配置情况(即EnableJpaAuditing,今天找到了spring mvc的配置方案,在springmvc配置文件中通过配置的方式,增加@CreatedDate、@CreatedBy、@LastModifiedDate、@LastModifiedBy 如下:

    首先实体类增加

    //实体通用继承类
    @MappedSuperclass
    @EntityListeners(AuditingEntityListener.class)

    字段增加(以创造时间为例)

    @Temporal(TemporalType.TIMESTAMP)//格式化时间
    @LastModifiedDate
     private Date createTime;

    还需要在pom文件中引上审计所需的包,不然会报Could not configure Spring Data JPA auditing-feature because spring-aspects.jar is not on the classpath!|If you want to use auditing please add spring-aspects.jar to the classpath.|的错误

      <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-aspects</artifactId>
                <version>${spring.version}</version>
            </dependency>

    最后在spring配置文件中增加,我的是spring-mvc.xml

    <jpa:auditing />

    最为关键的一句,作用和spring boot的

    在Application启动类中添加注解 @EnableJpaAuditing,一样!

    完!

  • 相关阅读:
    第六次上机作业
    NOIP2016 DAY1 T2天天爱跑步
    NOIP2009 T2 Hankson的趣味题
    NOIP2013 DAY2 T3火车运输
    线段树
    NOIP2012 DAY2 T2借教室
    NOIP2015 DAY2 T1跳石头
    NOIP2016 DAY2 T3 愤怒的小鸟
    文本编辑常用快捷键
    洛谷P1516 青蛙的约会
  • 原文地址:https://www.cnblogs.com/yangchas/p/12765299.html
Copyright © 2011-2022 走看看