私は単純なPOJOを持っています:
@Document(collection = "questions")
public class Question {
private String title;
private Date createdAt;
//..... all the getter and setters
}
作成後に変更してはならないので、編集フォームに createdAt を追加しませんでした。ただし、更新コントローラー メソッドは、バインドにより、createdAt で null 値を取得します。
@RequestMapping(method = RequestMethod.PUT, produces = "text/html")
public String update(@Valid Question question, BindingResult bindingResult,
Model uiModel, HttpServletRequest httpServletRequest) {
if (bindingResult.hasErrors()) {
populateEditForm(uiModel, question);
return "questions/update";
}
uiModel.asMap().clear();
questionRepository.save(question);
return "redirect:/questions/"
+ encodeUrlPathSegment(question.getId().toString(),
httpServletRequest);
}
したがって、質問を更新した後、createdAt フィールドはクリアされます。それを解決する方法はありますか?createdAt フィールドなしで別のクラスを作成して更新を行いたくありません。