【发布时间】:2013-04-17 19:10:17
【问题描述】:
在我的练习中,我必须开发一个可以通过 WebGUI 和 REST 服务访问的 spring 应用程序。 现在我浏览了 Spring MVC 的示例,有 this hello world 的 Spring MVC 教程。
控制器如下所示:
@Controller
@RequestMapping("/welcome")
public class HelloController {
@RequestMapping(method = RequestMethod.GET)
public String printWelcome(ModelMap model) {
model.addAttribute("message", "Spring 3 MVC Hello World");
return "hello";
}
}
然后我查看了Spring REST example,看起来像这样:
@Controller
@RequestMapping("/movie")
public class MovieController {
@RequestMapping(value = "/{name}", method = RequestMethod.GET)
public String getMovie(@PathVariable String name, ModelMap model) {
model.addAttribute("movie", name);
return "list";
}
@RequestMapping(value = "/", method = RequestMethod.GET)
public String getDefaultMovie(ModelMap model) {
model.addAttribute("movie", "this is default movie");
return "list";
}
}
现在我想知道,这两个示例(Spring-mvc 和 Spring-rest)有何不同? 它们都使用相同的注释并且工作相似。这两个不都只是 REST 示例吗?
如何为 Spring-MVC 应用程序提供 Rest-Interface?
问候
【问题讨论】:
-
RESTful 服务与访问资源的方式有关。见:en.wikipedia.org/wiki/…
标签: java spring rest web-applications spring-mvc