java - 注释 @DateTimeFormat 不适用于 Spring boot 和 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")
...
}
我的日期即将到来 yyyy-mm-dd。你知道我如何改变这个/在哪里实现代码,所以它会改变。它进入我的控制器吗?这是我发送获取用户输入日期的表单时的代码
@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>
推荐阅读
- python - 我如何用 python 解决我的 virtualenv 问题?
- xcode - 如何在 Xcode 中使用 AppleScript 创建一个简单的 kext 安装程序?
- java - 如何检查 NumberFormatException:空字符串
- android - 使用片段和底部导航栏
- xml - 替换 XML 文档中的属性值
- r - r中的条件apply()
- reactjs - 基本示例反应弹簧
- airflow - 如何加快新 dag 在 Apache Airflow 中显示到 Web GUI 的过程?
- python - 如何在日志中包含其他参数,例如 python-bunyan 中的函数名、行号、路径名
- php - 它没有在 RecyclerView 中显示数据库的记录。PHP 代码没问题,他们完美地创建了 json