springmvc自定义转换器
日期传值的时候出现错误,自定义一个转换器来实现 import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; //实现 converter接口 public class StringToDateConverter implements Converter<String, Date> { /** * 传过来的值 * @param s * @return */ @Override public Date convert(String s) { if(s == null){ throw new RuntimeException("请您传入参数"); } DateFormat df = new SimpleDateFormat("yyyy-MM-dd"); //把字符串转日期 try { return df.parse(s); } catch (ParseException e) { throw new RuntimeException("数据转行错误"); } } } 在springmvc的xml里配置参数 <!--自定义转换器--> <bean id="conversionServiceFactoryBean"