spring REST 之Hello World

来源:互联网 发布:淘宝联盟登录淘宝名 编辑:程序博客网 时间:2024/05/21 07:49

要运行更复杂的REST程序,需要chrome插件或者专门的客户端

package com.mkyong.common.controller;import org.springframework.stereotype.Controller;import org.springframework.ui.ModelMap;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;@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";}}
list.jsp

<html><body><h1>Spring 3 MVC REST web service</h1><h3>Movie Name : ${movie}</h3></body></html>
mvc-dispatcher-servlet.xml

<context:component-scan base-package="com.mkyong.common.controller" /><mvc:annotation-driven /><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix"><value>/WEB-INF/pages/</value></property><property name="suffix"><value>.jsp</value></property></bean>


原文:http://www.mkyong.com/spring-mvc/spring-3-rest-hello-world-example/

源代码:http://pan.baidu.com/share/link?shareid=2465317834&uk=3878681452