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

     效果展示

     

     三

     提交成功

  • 相关阅读:
    ::before和::after伪元素的用法
    JS中map、some、every、filter方法
    C++多线程,互斥,同步
    RAII
    Proxy 代理
    Decorator 装饰
    TCP和UDP的9个区别是什么
    谈谈自己对面向对象的理解
    C++11多线程
    std::move
  • 原文地址:https://www.cnblogs.com/baixingqiang/p/6260042.html
Copyright © 2011-2022 走看看