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,一样!

完!

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM