import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** * 请求映射的第一种方式 * @author xieke */ @Controller @RequestMapping("/test_url_one") public class TestOneController { /** * web.xml中servlet-mapping的配置 * <servlet-mapping> * <servlet-name>dispatcher</servlet-name> * <!-- 表示拦截所有/XX的请求 --> * <url-pattern>/</url-pattern> * </servlet-mapping> * * 请求方式: * http://IP地址:端口号/项目名称/类请求映射名称/方法请求映射名称 * 比如: * http://127.0.0.1:1314/SpringMVC_URL/test_url_one/index */ @RequestMapping("/index") public String testOne(){ return "success"; } }
测试结果如下:
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; /** * 请求映射的第二种方式 * @author xieke */ @Controller @RequestMapping("/test_url_two") public class TestTwoController { /** * web.xml中servlet-mapping的配置 * <servlet-mapping> * <servlet-name>dispatcher</servlet-name> * <!-- 表示拦截所有XX.do的请求 --> * <url-pattern>*.do</url-pattern> * </servlet-mapping> * * 请求方式: * http://IP地址:端口号/项目名称/类请求映射名称/方法请求映射名称.do * 比如: * http://127.0.0.1:1314/SpringMVC_URL/test_url_two/index.do */ @RequestMapping("/index") public String testTwo(){ return "success"; } }
测试结果如下:
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; /** * 请求映射的第三种方式 * @author xieke */ @Controller @RequestMapping("/test_url_three.do") public class TestThreeController { /** * web.xml中servlet-mapping的配置 * <servlet-mapping> * <servlet-name>dispatcher</servlet-name> * <!-- 表示拦截所有XX.do的请求 --> * <url-pattern>*.do</url-pattern> * </servlet-mapping> * * 请求方式: * http://IP地址:端口号/项目名称/类请求映射名称/方法请求映射名称?params * 比如: * http://127.0.0.1:1314/SpringMVC_URL/test_url_three.do?method=index */ @RequestMapping(params="method=index",method=RequestMethod.GET) public String testThree(){ return "success"; } }
测试结果如下:
转载请注明出处: http://xieke90.iteye.com/blog/2235706