Spring mvc 数据绑定 String 绑定 Date
2017-12-26 13:22
232 查看
package com.ccm.credit.manager.menu.impl; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import org.springframework.format.Formatter; import org.springframework.stereotype.Service; @Service public class DateFormater implements Formatter<Date>{ @Override public String print(Date object, Locale locale) { // TODO Auto-generated method stub return null; } @Override public Date parse(String text, Locale locale) throws ParseException { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-DD HH:mm:ss"); return sdf.parse(text); } }
Spring boot 中 :formatter 接口 默认返回值是String,还可以实现Converter接口 用来自定义返回类型
Spring 中需要增加以下配置
//数据绑定(String绑定date)
<mvc:annotation-driven conversion-service="DateFormater"/>
<bean id="DateFormater" class="org.springframework.format.support.FormattingConversionServiceFactoryBean">
<property name="DateFormater">
<set>
<bean class="com.testone.Controller.DateFormater"></bean>
</set>
</property>
</bean>
相关文章推荐
- spring mvc绑定对象String转Date解决入参不能是Date的问题
- spring mvc绑定对象String转Date
- spring mvc3(对象传参 Date 类型数据绑定)
- spring mvc绑定对象String转Date
- spring mvc绑定对象String转Date
- spring mvc绑定对象String转Date
- @InitBinder对表单数据绑定解决String转换Date问题
- spring mvc 数据绑定报错 Failed to convert property value of type 'java.lang.String' to required type 'int'
- spring mvc使用@InitBinder 标签对表单数据绑定
- Spring MVC数据绑定大全
- Spring MVC数据绑定大全
- Spring MVC数据绑定大全
- Spring mvc 提交时间 String Date 的转换问题
- js,Array转换成json数据,传给后台String[]参数(基于Spring MVC)
- Spring MVC自定义数据绑定--HandlerMethodArgumentResolver
- spring mvc时间string转Date问题(一)
- Spring MVC数据绑定
- spring mvc 数据绑定
- asp.net的eval,bind,container.dateitem,数据绑定的研究
- Spring MVC 数据绑定