【发布时间】:2015-05-22 20:42:17
【问题描述】:
我有以下控制器:
@RequestMapping(value="/usage", method=RequestMethod.GET)
public String usage(Model model) {
CallDataRecordLine calldatarecordline = new CallDataRecordLine();
model.addAttribute("calldatarecordline",calldatarecordline);
return "usage";
}
@RequestMapping(value="/usage", method=RequestMethod.POST)
public String greetingSubmit(@ModelAttribute CallDataRecordLine calldatarecordline, Model model) {
model.addAttribute("calldatarecordline",calldatarecordline);
return "result";
}
实体描述如下
public class CallDataRecordLine {
int chargedQuantity;
String fromNumber;
String toNumber;
DateTime dt;
String usage;
String chargeableQuantity;
//getters/setters
}
以及链接到控制器的视图
<form id="calldatarecordForm" class="form-horizontal" role="form"
action="#" th:action="@{/usage}" th:object="${calldatarecordline}"
method="post">
<input type="text" th:field="*{fromNumber}" class="form-control" /> <input
type="text" th:field="*{toNumber}" class="form-control" /> <input
type="datetime" th:field="*{dt}" class="form-control" /> <input
type="text" th:field="*{chargedQuantity}" class="form-control" /> <input
type="text" th:field="*{usage}" class="form-control" /> <input
type="text" th:field="*{chargeableQuantity}" class="form-control" />
<button type="submit">Test</button>
</form>
显然,th:field 无法转换 jodaTime DateTime(我尝试删除 dt 属性并正确创建了 CallDataRecordLine)。我看到可以使用转换器/格式化程序,但我正在使用 spring-boot,我真的不知道该怎么做,因为所有配置都是自动加载的。我尝试了两种输入类型=“文本”/“日期时间”,都没有工作 非常感谢您的帮助。
【问题讨论】:
标签: datetime converter spring-boot jodatime thymeleaf