类型转换器(InitBinder 初始化绑定器)

单日期格式

导入jar包

 

创建FirstController.java

 @Controller
	public class FirstController {
    	 /**
    	  * @param binder
    	  */
    	 
    	@InitBinder
    	public void initBinder(WebDataBinder binder){
    		//PropertyEditor
    		//类  implements  PropertyEditor
          //yyyy-MM-dd格式的时间 binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true)); } @RequestMapping("/first.do") //类型转化工作一定是在真正的handler方法执行前执行的。 public String doFirst(Date birthday,int age) throws Exception{ System.out.println(birthday+"==============="); System.out.println(age+"==============="); return "/WELCOME.jsp"; } }

applicationContext.xml配置  包扫描器

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:mvc="http://www.springframework.org/schema/mvc" 
     xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
        ">
     
   <!-- 配置包扫描器-->
       <context:component-scan base-package="cn.happy.controller"></context:component-scan>
</beans>

效果展示图

 

 提交成功

多日期格式

 与单日期jar包相同

 效果展示

 

 

 三

 提交成功

 

posted @ 2017-01-07 18:53  白兴强  阅读(132)  评论(0编辑  收藏  举报