首页 > 其他 > 详细

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

时间:2017-01-07 19:49:01      阅读:189      评论:0      收藏:0      [点我收藏+]

单日期格式

导入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包相同

 效果展示

技术分享

 技术分享

 

 三

技术分享

 提交成功

技术分享

 

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

原文:http://www.cnblogs.com/baixingqiang/p/6260042.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!