I'm writing a program in Spring boot and my database is postgre. i have a problem with thymeleaf. I try to input a localdate value but the value remain null. i dont have any problem with another values like String and int.
This is my Localdate value:
@DateTimeFormat(pattern="yyyy-MM-dd")
private LocalDate einkaufsdatum;
and this is my thymeleafs code:
<form action="#" th:action="@{/addmaterial}" th:object="${material}" method="post">
<p>Einkaufsdatum: <input type="date" th:value="*{einkaufsdatum}" />
</form>
and this is my controller:
@RequestMapping(value="addmaterial", method=RequestMethod.POST)
public String addSpeichern(@ModelAttribute Material material) {
// System.out.println(material.getEinkaufsdatum()); for testing: print null value!
materialRepository.save(material);
return "materialverwaltung";
}
I found the problem: instead of:
<p>Einkaufsdatum: <input type="date" th:value="*{einkaufsdatum}" />
i used this:
<p>Einkaufsdatum: <input type="date" th:field="*{einkaufsdatum}" />
Instead of:
@DateTimeFormat(pattern="yyyy-MM-dd")
private LocalDate einkaufsdatum;
Try this:
@DateTimeFormat(pattern="yyyy-MM-dd")
private LocalDate einkaufsdatum = LocalDate.now();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.