【发布时间】:2018-08-25 18:17:45
【问题描述】:
我收到这个错误,你能找出我做错了什么吗?
无法将“java.lang.String”类型的值转换为所需类型 java.time.LocalDate' 嵌套异常是 java.lang.IllegalStateException:无法转换类型的值 'java.lang.String' 到所需类型'java.time.LocalDate':没有匹配 找到编辑器或转换策略。
package com.pc.controller;
import java.time.LocalDate;
import java.util.Map;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class Controllera {
@RequestMapping(value="/home.htm",method=RequestMethod.GET)
public String showForm() {
System.out.println("Controllera.showForm()");
return "welcome";
}
@RequestMapping(value="/home.htm",method=RequestMethod.POST)
public String process(Map<String ,Object>map,@RequestParam("date")
@DateTimeFormat(pattern="dd-MM-yyyy") LocalDate date) {
System.out.println("Controllera.process()");
System.out.println(date);
map.put("date",date);
return "success";
}
}
//end of controller
My web page
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<form method="POST">
<input type="text" name="date" id="date"/><br>
<input type="submit"/>
</form >
【问题讨论】:
-
我建议您将
date参数定义为字符串并在process(...)处理程序中进行转换
标签: spring-mvc