app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
Archetype Created Web Application
CharacterEncodingFilter
class>org.springframework.web.filter.CharacterEncodingFilterclass>
encoding
UTF-8
forceRequestEncoding
true
forceResponseEncoding
true
CharacterEncodingFilter
/*
springmvc
org.springframework.web.servlet.DispatcherServlet
contextConfigLocation
classpath:spring-mvc.xml
springmvc
/
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;
@Controller
public class FirstController {
@InitBinder
public void initBinder(WebDataBinder binder) {
//registerCustomEditor:为给定类型的所有属性注册给定的定制属性编辑器。
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
}//CustomDateEditor:定义日期格式,覆盖默认的日期格式,允许为空
@RequestMapping("/first")
//类型转化工作一定是在真正的handler方法执行前执行的。
public String doFirst(Date birthday, int age) {
System.out.println(birthday + "================");
System.out.println(age + "=============");
return "/index.jsp";
}
}
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
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">
package="cn.happy.controller"/>