您的位置:首页 > 编程语言 > Java开发

springMVC日期转换及The request sent by the client was syntactically incorrect.解决办法

2017-01-18 16:37 776 查看
今天在前端通过日期插件查询时出现错误:



springMVC参数错误。细查之后原来是因为前端传过去的是String类型,而接受数据的类型为Date类型,这时有2中解决办法:

一、日期格式转换:

通过SimpleDateFormat.parse(“”)把参数格式化为Date类型。

二、通过springMVC.xml配置日期转换。

在springMVC的xml配置文件中添加如下代码:

<mvc:annotation-driven conversion-service="conversionService" />
<bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="registerDefaultFormatters" value="true" />
<property name="formatterRegistrars">
<set>
<bean class="org.springframework.format.datetime.DateFormatterRegistrar">
<property name="formatter" ref="dateFormatter"></property>
</bean>
</set>
</property>
</bean>

<bean id="dateFormatter" class="org.springframework.format.datetime.DateFormatter">
<property name="pattern" value="yyyy-MM-dd"></property>
</bean>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐