所以我通过创建一个对象并调用create方法并在存储对象时设置创建日期来创建新内容,它将日期修改为当前日期。请帮助将旧日期保存在数据库中。下面是来自控制器之一的行
Content newContent = this.contentService.create(this.contentUtils.getEditedContentFromOldContent(oldContent,contentDto));
Paramter方法.....
public Content getEditedContentFromOldContent(Content oldContent, ContentDto contentDto) throws APIException {
Content content = this.beanMapper.map(contentDto, Content.class);
content.setId(null);
content.setCreateDate(oldContent.getCreateDate());
content.setLastModifiedDate(new Date());
content.setUpdatedBy(oldContent.getUpdatedBy());
content.setUser(oldContent.getUser());
ContentCategory contentCategory = this.contentCategoryService.get(contentDto.getCategoryId());
if (null == contentCategory) {
throw new APIException("Invalid category Id :: " + contentDto.getCategoryId());
}
content.setContentCategory(contentCategory);
return content;
}
创建方法
public Content create(Content content) throws ServiceException {
if (contentAccessUtil.getAccess(content, "UPLOAD_CONTENT")) {
return contentRepository.save(content);
} else {
throw new ServiceException("Access Denied");
}
}
Pojo类创建日期
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "create_date", updatable = false, nullable = false)
private Date createDate;
我已经调试了oldcontent.getcreate日期的值,这是02-05-2015,当我设置此值时,数据库仍然存储当前日期,我想存储上一个日期。如果有人可以帮我解决这个问题会很棒。在数据库中,创建日期的类型是日期时间。