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

    完!

  • 相关阅读:
    ObjectForScripting 注册
    取消mysql表中timestamp字段的自动更新
    分片与非分片使用聚合的区别
    java类加载过程
    springboot中使用solr8
    第四章
    获取cookie的两种方式和session共享解决方案
    剑指 Offer 57. 和为s的两个数字
    第三章
    第五章
  • 原文地址:https://www.cnblogs.com/yangchas/p/12765299.html
Copyright © 2011-2022 走看看