gpt4 book ai didi

java - 注释 @DateTimeFormat 不适用于 Spring boot 和 Thymeleaf

转载 作者:行者123 更新时间:2023-11-30 05:59:26 24 4
gpt4 key购买 nike

我正在使用 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")
...
}

我的约会将于年月日确定。你知道我如何改变这个/在哪里实现代码以便它改变吗?它在我的 Controller 中吗?这是我发送获取用户输入日期的表单时的代码

@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";
}

最佳答案

使用#temporals让它工作!

<tr class="emailRow">
<td colspan="1" class="dateRangeEnd" th:text="${#temporals.format(directBind.policyTermDateEnd, 'MM/dd/yyyy')}">
</td>
</tr>

关于java - 注释 @DateTimeFormat 不适用于 Spring boot 和 Thymeleaf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52522899/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com