------------I do not have him, but the hand is ripe, humble and foolish, and eager to be hungry-------------
Before the configuration date type converter of the blog, he is global, what if it is only used in a processor?
Elicit @initbinder annotations
Case:
1. In the Processor:
Package Cn.dawn.day22initbinder;import Org.springframework.beans.propertyeditors.customdateeditor;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.webdatabinder;import Org.springframework.web.bind.annotation.initbinder;import Org.springframework.web.bind.annotation.requestmapping;import Java.text.simpledateformat;import java.util.Date;/** * Created by Dawn on 2018/3/31.*/@Controller Public classFirstcontroller {/*First Kind*/ /*@InitBinder*/ /*The second Kind*/@InitBinder ("Birthday") Public voidInitbinder (Webdatabinder binder) {System. out. println ("1111111111"); SimpleDateFormat SDF=NewSimpleDateFormat ("YYYY-MM-DD"); Binder.registercustomeditor (Date.class,NewCustomdateeditor (SDF,true)); } /*Initbinder*/@RequestMapping ("/initbinderfirst") Publicstring Initbinderfirst (string username, Integer userage, Date birthday) throws Exception {System. out. println ("2222222222"); System. out. println (username); System. out. println (Userage); System. out. println (birthday); return "Success"; }}
Here it is important to explain a wave, so that the date type converter can become local, two methods to execute the order as the output of a 1, a 2, @InitBinder note It plus the parameter is said to only match birthday, if not add, the following method has three parameters, The above method executes three times, System.out.print ("11111111") three times
2. Your own XML configuration file:
<?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:mvc="Http://www.springframework.org/schema/mvc"Xmlns:context="Http://www.springframework.org/schema/context"xsi:schemalocation="Http://www.springframework.org/schema/beanshttp//www.springframework.org/schema/beans/spring-beans.xsdhttp//Www.springframework.org/schema/mvchttp//www.springframework.org/schema/mvc/spring-mvc.xsdhttp//Www.springframework.org/schema/contexthttp//www.springframework.org/schema/context/spring-context.xsd "><!--package Scanner--<context:component-scanBase-package="Cn.dawn.day22initbinder"></context:component-scan> <!--View Resolver-<beanclass="Org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix"Value="/day22/"></property> <property name="suffix"Value=". JSP"></property> </bean></beans>
3. Modify the central scheduler of the Web. XML configuration file to configure the location for the upper
4.jsp page:
4.1login.jsp
<%@ page pageencoding="UTF-8"Contenttype="Text/html;charset=utf-8"Language="Java"Iselignored="false"%>"${pagecontext.request.contextpath}/initbinderfirst"Method="Post">User name:<input name="username"Value="${username}">Age:<input name="Userage">Birthday:<input name="Birthday"> <input type="Submit"Value="Login"/></form></body>4.2success.jsp page
<%@ page language="java" pageencoding="utf-8" iselignored ="false" %>"image/1. JPG">--%>
5. Start Tomcat, Access login.jsp, found that only YYYY-MM-DD can be converted successfully, that it has and springmvc default difference, the same problem, compatibility is not good, so the next blog for everyone to do further optimization
Preliminary study of Initbinder in SSM-SPRINGMVC-29:SPRINGMVC