Spring注解@RequestMapping请求路径映射问题
2015-08-21 13:54
477 查看
原文链接:http://www.cnblogs.com/jeofey/p/7227039.html
@RequestMapping请求路径映射,如果标注在某个controller的类级别上,则表明访问此类路径下的方法都要加上其配置的路径;最常用是标注在方法上,表明哪个具体的方法来接受处理某次请求。
以下两种方式都可以从url中传参数,但是第二种方式的适用性更高一些,当参数中包含中文的时候,如果用第一种方式传参数,经常会出现参数还没到controller就已经经过编码了(例如:经过utf-8编码后,原本要传的参数就会以%+ab...cd这样的方式出现),然后controller接受到这样的请求后,根本无法解析该请求应该走那个业务方法。然后就会出现常见的404问题。。。
package com.test.jeofey.web; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/path") public class TestController { // 第一种传参数的方式 访问地址例如:http:域名/path/method1/keyWord.html @RequestMapping("method1/{keyWord}") public String getZhiShiDetailData(@PathVariable("keyWord") String keyWord, HttpServletRequest request, HttpServletResponse response){ System.out.println(keyWord); return "v1/detail"; } // 第二种传参数的方式 访问地址例如:http:域名/path/method2.html?key=keyWord @RequestMapping("method2") public String getCommonData(HttpServletRequest request, HttpServletResponse response){ String keyWord= request.getParameter("key"); System.out.println(keyWord); return "v1/common"; } }
转载于:https://www.cnblogs.com/jeofey/p/7227039.html
相关文章推荐
- Spring注解@RequestMapping请求路径映射问题
- Spring注解@RequestMapping请求路径映射问题
- spring的requestmapping注解问题
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- 1.2、映射请求注解@RequestMapping的请求参数和请求头用法
- SpringMVC Spring3 MVC 注解,注释 用@RequestMapping处理请求,多个请求,提交,.do,带参数,url重写
- SpringMVC(二) 请求地址映射 @RequestMapping注解
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- 关于spring-mvc请求路径的问题
- SpringMVC Spring3 MVC 注解,注释 用@RequestMapping处理请求,多个请求,提交,.do,带参数,url重写
- SpringMVC Spring3 MVC 注解,注释 用@RequestMapping处理请求,多个请求,提交,.do,带参数,url重写
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- Spring 4.3 新增加的请求注解,对@RequestMapping()进行了细分
- Spring注解@RequestMapping请求路径映射问题
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射
- Struts2一个Action内包含多个请求处理方法的处理,method的使用方法,struts2中的路径问题,通配符映射 (
- 使用@RequestMapping映射请求路径
- 1.1、映射请求注解RequestMapping用法
- spring boot 使用Aop通知打印控制器请求报文和返回报文问题
- spring中的RequestMapping的四种请求方式