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

    完!

  • 相关阅读:
    常用的STL
    CString,string,char数组的转换
    linux知识
    十一种通用滤波算法(转)
    修复被勒索病毒cl0p损坏的svn代码
    android shell 转发代理shell示例
    3proxy配置
    windbg调试写dmp,随机名字
    nexus6p刷机注意
    mysql语句学习
  • 原文地址:https://www.cnblogs.com/yangchas/p/12765299.html
Copyright © 2011-2022 走看看