java - @CreatedDate 不起作用,但 @UpdatedDate 正在为第一次保存工作
问题描述
我尝试使用@CreatedDate 和@LastModifiedDate。虽然 @LastModifiedDate 工作正常,但 @CreatedDate 不是。
我在主应用程序配置文件中添加了@EnableMongoAuditing。
主应用程序.java
public class Application {
public static void main(String[] args) {
ApplicationContext applicationContext =
SpringApplication.run(Application.class, args);
}
}
评论.java
@Entity
public class Comment {
@Id
String commentId;
@NotNull
String userId;
@CreatedDate
Date CreatedDate;
@LastModifiedDate
Date UpdatedDate;
getters, setters .,,
}
评论DAO.java
public class CommentDAO{
@Autowired
MongoTemplate mongoTemplate;
public Comment addComment(Comment comment) {
return mongoTemplate.save(comment, "Comment");
}
}
控制器.java
@annotations
class controller
{
@GetMapping("/hello")
public Comment check()
{
Comment c=new Comment();
c.setId("0.07864261262777905");
c.setUserId("kli");
c.setAnonymus(false);
return commentDAO.addComment(c);
}
}
结果是
commentId "0.07864261262777905"
userId "kli"
content null
anonymus false
createdDate null
updatedDate "2019-01-19T08:36:42.573+0000"
解决方案
推荐阅读
- ios - Apple 工资单未显示给 Apple 应用审查员
- reactjs - 关键帧在嵌套 SVG 中不起作用,但在单个 SVG 中起作用
- c - CS50 有效三角形 - 错误的代码输出
- julia - 获取 Julia 方法的关键字名称
- ios - EKCalendarChooser 委托不在 NSObject 中工作
- python - 是否可以在 numpy 版本 1.7.1 中使用 numpy 特征向量计算出现分段错误
- python - 如何将单列 QVBoxLayout 修改为多列?
- c++ - 在 C++ 代码中使用 parfor 关键字并行化 for 循环
- c# - C# REST API - 如何使用错误代码扩展模型状态错误
- javascript - 在 PDF 中嵌入 JavaScript/操作向导