//the parameter was converted in initBinder
@RequestMapping("/date")
public String date(Date date){
System.out.println(date); return "hello";
}
//At the time of initialization,convert the type "String" to type "date" @InitBinder
public void initBinder(ServletRequestDataBinder binder){
binder.registerCustomEditor(Date.class, new CustomDateEditor(new SimpleDateFormat("yyyy-MM-dd"), true));
}
Spring MVC基础知识总结:史上最全的SpringMVC学习笔记。在第十七节,作者只是提出了要建两个容器配置文件(applicationContext.xml和xxx-servlet.xml),并通过exclude和include配置防止bean的重复加载,不过没有深入讲解其背后的原因。
Spring 容器(Spring 的上下文)这篇文章给出了详细解释:在Spring MVC项目中,这两个父子容器的角色不同:(1)父容器中保存数据源、服务层、DAO层、事务的Bean;(2)子容器中保存Mvc相关的Action的Bean。对应到例子中,applicationContext.xml定义父容器,xxx-servlet.xml定义子容器。
引用官方文档中的一张图片,可以清晰地看出dispatcherservlet上下文和Root应用上下文之间的关系:Root应用上下文用于提供service、数据库等bean,可供多个dispatcherservlet上下文使用。