[英]Annotation @DateTimeFormat not working with Spring boot and Thymeleaf
I am using Springboot, Java, and Thymeleaf.我正在使用 Springboot、Java 和 Thymeleaf。
public class DirectBind {
@Column(columnDefinition = "date")
@DateTimeFormat(pattern = "MM/dd/yyyy")
private LocalDate policyTermDateStart;
@Column(columnDefinition = "date")
@DateTimeFormat(pattern = "MM/dd/yyyy")
...
}
My date is coming out yyyy-mm-dd.我的约会对象是 yyyy-mm-dd。 Do you know how I can change this/where to implement the code so it changes.您知道我如何更改此代码/在何处实现代码以使其更改。 Does it go in my controller?它会进入我的控制器吗? This is my code for when I send the form that's grabbing the user input for date这是我发送获取用户输入日期的表单时的代码
@RequestMapping(value = "/send")
public String send(Model model, @ModelAttribute(value = "directBind") DirectBind directBind) {
List<String> businessAgencyList = directBind.getBusinessAgencyList();
List<String> billTypeOptions = directBind.getBillTypeOptions();
Mail mail = new Mail();
mail.setFrom("no-reply@hgitservices.com");
mail.setTo(new String[]{"stacief@hgitservices.com"});
mail.setSubject("Oli Affiliate - AMS360 & PMA Data Checklist");
Map<String, Object> mailModel = new HashMap<>();
mail.setModel(mailModel);
try {
emailService.sendSimpleMessage(mail, directBind);
} catch (Exception e) {
e.printStackTrace();
return ("redirect:/?sentMessageFail");
}
return ("redirect:/?sentMessage");
}
@RequestMapping(value = "/email")
public String email() {
return "emailMessage";
}
Got it to work using #temporals!使用#temporals 让它工作!
<tr class="emailRow"> <td colspan="1" class="dateRangeEnd" th:text="${#temporals.format(directBind.policyTermDateEnd, 'MM/dd/yyyy')}"> </td> </tr>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.