相信很多同学一定遇到过这个错误,最烦的是这个错误再后台是没有明显表现的。(连debug都进不去)
反正我是被这个问题折腾了一上午,也许是我很菜咯。
=========================分割线
一开始由于进不到我后台,而后台又不显示错误,so....我把spring日志级别调整到debug级别,终于找出原因了:
- [DEBUG][2013/04/28 12:19:10,561][org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver] - Resolving exception from handler [com.xdtech.cloudsearch.module.config.index.action.FieldAction@44b46c4c]: org.springframework.beans.TypeMismatchException:<span style="color:#ff6666;"> Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "23-05-2013" from type 'java.lang.String' to type 'java.util.Date'; nested exception is java.lang.IllegalArgumentException
- </span>
这个错误是SpringMVC报出来的,见到它意味着html/jsp页面的控件名称 和 controller里函数的参数不符。
由于我传的date类型,而对应的函数参数应该这样写:
String date1 = request.getParameter("date");
<span style="font-family:verdana, Arial, Helvetica, sans-serif;"><span style="line-height: 25.2px;"> SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
</span></span><span style="line-height: 25.2px; background-color: rgb(240, 240, 240);"> </span><span style="font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; background-color: rgb(248, 248, 248);">java.util.Date </span><span class="attribute" style="font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; margin: 0px; padding: 0px; border: none; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; color: red; background-color: rgb(248, 248, 248);">date</span><span style="font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; margin: 0px; padding: 0px; border: none; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; background-color: rgb(248, 248, 248);">=</span><span class="attribute-value" style="font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; margin: 0px; padding: 0px; border: none; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; color: blue; background-color: rgb(248, 248, 248);">sdf</span><span style="font-family: Consolas, 'Courier New', Courier, mono, serif; line-height: 18px; margin: 0px; padding: 0px; border: none; border-image-source: initial; border-image-slice: initial; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; background-color: rgb(248, 248, 248);">.parse(<span style="font-family: verdana, Arial, Helvetica, sans-serif; line-height: 25.2px; background-color: rgb(240, 240, 240);">date1</span>); </span>
查看文章
点击打开链接