SpringMVC中的@RequestMapping
来源:互联网 发布:windows xp主题下载 编辑:程序博客网 时间:2024/06/05 19:00
关于@RequestMapping注释中的参数:
params参数:用来处理带有指定参数的请求。
可以用它来请求同一个父路径却下的不同方法。
@Controller@RequestMapping("/getRequest.do")public class TestController { @RequestMapping(params = "method=text1") public String getRequest01(HttpServletRequest request, HttpServletResponse response) { return "sucess"; } @RequestMapping(params = "method=text2") public String getRequest02(HttpServletRequest request, HttpServletResponse response) { return "fail"; }}
我们可以看到上面这段代码有两个不同的方法,getRequest01()与getRequest02()。这两个方法都有相同的父路径:/getRequest。他们都使用了@RequestMapping注释。在注释中,params参数的属性不同。
在我们发送请求的时候,url中的特定参数值会决定访问哪个方法。
url: getRequest.do?method=text1
这个就会访问getRequest01这个方法。
url: getRequest.do?method=text2
这个就会访问getRequest02这个方法。
produces 参数:
我们可以看一下源码中的注释
The producible media types of the mapped request, narrowing the primary mapping. * <p>The format is a single media type or a sequence of media types, * with a request only mapped if the {@code Accept} matches one of these media types. * Examples: * <pre class="code"> * produces = "text/plain" * produces = {"text/plain", "application/*"} * </pre> * Expressions can be negated by using the "!" operator, as in "!text/plain", which matches * all requests with a {@code Accept} other than "text/plain". * <p><b>Supported at the type level as well as at the method level!</b> * When used at the type level, all method-level mappings override * this produces restriction. * @see org.springframework.http.MediaType
- 只有请求头的accept中的类型和produces的值相匹配,才会进行映射。
produces = {"text/plain", "application/*"}
- 也可以指定通过!来指定不映射的类型。
produces="!text/plain"
- 当我们在类上使用这个属性的时候,类中方法的映射都会被覆盖
未完待续…
阅读全文
0 0
- springmvc注解中的@requestmapping
- SpringMVC中的@RequestMapping
- springMVC中的@RequestMapping的作用
- SpringMVC中的@RequestMapping注解中的@PathVariable注解
- SpringMVC中的RequestMapping修饰类注解
- springMVC @RequestMapping
- @RequestMapping-------springMVC
- SpringMVC requestMapping
- SpringMVC --@RequestMapping
- springmvc中的@RequestMapping注解中的return "redirect:/";的用法。
- 由SpringMVC中的Controller注解@RequestMapping引发的思考
- SpringMVC 的@RequestMapping注解
- Springmvc @RequestMapping 用法
- SpringMVC RequestMapping 参数详解
- SpringMVC @RequestMapping 1
- SpringMVC @RequestMapping 2
- SpringMVC-02 RequestMapping注解
- SpringMVC RequestMapping注解详解
- mfc 的 clistctrl 显示item的最大长度
- iOS OpenGL 纹理坐标详解
- 在齐次方程组中为什么当系数矩阵的秩r比n小时,方程组的基础解系有(n-r) 个?
- Sudoku Killer HDU
- 单例模式再看
- SpringMVC中的@RequestMapping
- Nginx提高并发量的简单思路
- 系统rhel7本地yum源的配置
- python_fullstack基础(二)
- Hybris入门详解一BY.Shaun-sheng
- poj 多项式加法 map
- yii2 遇到的小方法
- spring中读取property的几种方式及解析
- python︱apple开源机器学习框架turicreate中的SFrame——新形态pd.DataFrame