【发布时间】:2017-01-28 17:43:58
【问题描述】:
<form th:action="@{home}" method="get">
<div class="form-group">
<label>from date:</label> <input type="date" pattern="yyyy-MM-dd" name="d1" th:value="${d1}" />
<label>to date:</label> <input type="date" pattern="yyyy-MM-dd" name="d2" th:value="${d2}" />
<button type="submit">Trouver</button>
</div>
</form>
这是控制器代码部分:
@RequestParam(name = "d1", defaultValue = "1900-01-01") @DateTimeFormat(pattern = "yyyy-MM-dd") Date d1,
@RequestParam(name = "d2", defaultValue = "2200-01-01") @DateTimeFormat(pattern = "yyyy-MM-dd") Date d2){
我收到这条消息:
出现意外错误(类型=错误请求,状态=400)。失败的 将 [java.lang.String] 类型的值转换为所需类型 [java.util.Date];嵌套异常是 org.springframework.core.convert.ConversionFailedException: 失败 从类型 [java.lang.String] 转换为类型 [@org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.util.Date] 价值 'Wed Jun 08 00:00:00 WET 2016';嵌套异常是 java.lang.IllegalArgumentException:值的解析尝试失败 [2016 年 6 月 8 日星期三 00:00:00 WET]
【问题讨论】:
-
你能出示你的日期类型声明吗?或尝试像这样添加@DateTimeFormat(pattern = "yyyy-MM-dd"):@DateTimeFormat(pattern = "yyyy-MM-dd") private Date your_variable;
标签: java spring hibernate spring-mvc