我找不到在datbase中显示“生日”字段的正确方法! 即使当我尝试将新值提交给db时,它也不起作用。我在做什么错了?
这是我的代码:
控制器
@RequestMapping(value = {"/settings"}, method = RequestMethod.GET)
public ModelAndView settings() {
ModelAndView model = new ModelAndView();
model.addObject("user", user);
model.addObject("countries", getListOfCountries());
model.setViewName("user/settings");
return model;
}
@RequestMapping(value = {"/settings"}, method = RequestMethod.POST)
public ModelAndView updateUserGeneralSettings(@ModelAttribute User user) {
ModelAndView model = new ModelAndView();
userService.update(user);
model.addObject("user", user);
model.addObject("countries", getListOfCountries());
model.setViewName("user/settings");
return model;
}
HTML
<form method="POST" th:action="@{/settings}" th:object="${user}">
<div>
</div>
...
...
<div class="costum-field">
<label for="dateOfBirth" th:text="#{field.dateOfBirth}"></label>
<input type="date" id="dateOfBirth" class="form-control" th:field="*{dateOfBirth}"/>
</div>
...
...
<div>
</div>
</form
因此,如您所见,所有字段均正常工作。请提出我的错误。