zoukankan      html  css  js  c++  java
  • 类型转换器(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包相同

     效果展示

     

     三

     提交成功

  • 相关阅读:
    Android SDK manager 无法更新解决方法
    platform_set_drvdata的源码分析
    从一个男人身上看出他的修养和抱负
    更换RAID1硬盘过程记录
    无线路由器连接有线路由器设置
    在ASP.NET下实现数字和字符相混合的验证码 (转载)
    不走寻常路 设计ASP.NET应用程序的七大绝招
    .NET 2005 使用MasterPages实现Web窗体模板
    用Visual C# 实现四则混合运算(转载)
    如何实施好CRM (转载)
  • 原文地址:https://www.cnblogs.com/baixingqiang/p/6260042.html
Copyright © 2011-2022 走看看