Date

第一步

实现 Convert 接口

public class StringToDate implements Convert<String,Date>{
      public Date convert(String source){
            if(source == null){
                 throw new RuntimeException("请您输入数据");
            }
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
            try{
                  return df.parse(source );
            }catch(Exception e){
                  throw new RuntimeException("请您输入数据");
            }
      }
}

第二步

springmvc.xml
<!--配置自定义类型转换器-->
<bean id = "XXX" class = "XXXXX.ConversionServicinvertersceFactoryBean">
      <property name="converts">
            <set>
                  <bean class="com.leavescai.utils.StringToDate"/> //自定义转换器得全路径
            </set>
      </property>
</bean>

第三步

springmvc.xml
<!-- 开启扫描 -->
<mvc:annotation-driven conversion-service="conversionService"/>
posted on 2020-12-04 09:41  LeavesCai7  阅读(68)  评论(0)    收藏  举报