Spring的AbstractCommandController的替换

时间:2010-08-30 20:54:53

标签: java spring-mvc

我正在尝试从Spring In Action第2版(涵盖Spring 2.0)学习Spring MVC。

我的IDE告诉我AbstractCommandController已被弃用。它被替换了吗?处理案例的推荐方法是什么?{}}}

4 个答案:

答案 0 :(得分:4)

从Spring 3.0开始,整个Controller层次结构已被弃用,并被注释式控制器取代。这使事情变得相当简单,您不再需要担心要扩展哪些基类。

实际上,您甚至不会再在Spring参考手册中找到旧的层次结构,只需new annotation-style

带注释的控制器通过方法参数的简单自动绑定执行与AbstractCommandController相同的功能,例如

@Controller
public class MyController {

    @RequestMapping
    public String handleMe(Command command) {
       ...
    }
}

答案 1 :(得分:2)

就像AbstractCommandController的javadoc所说:

  

@deprecated从Spring 3.0开始,支持带注释的控制器

所以,看看spring reference documentation for annotated controllers

答案 2 :(得分:1)

你的书涵盖了Spring 2.0,它依赖于AbstractCommandController的子类。在Spring 2.5中,AbstractCommandController的等价物是AbstractController。在Spring 3.0中(正如其他人指出的那样),等价物是一个正确注释的@Controler类。

答案 3 :(得分:1)

Here是我写的一个关于使用基于注释的Spring MVC的简单示例,它可能有助于您入门。

它是this series的一部分。