zoukankan      html  css  js  c++  java
  • @RequestMapping注解详解

    @RequestMapping是一个用来处理请求地址映射的注解,可用于类或者方法上。用于类上,表示类中的所有响应请求的方法都是以该地址作为父路径。@RequestMapping注解有六个属性,下面进行详细的说明。

    1.value, method.

    value:指定请求的实际地址,指定的地址可以是URI Template模式。

    method:指定请求的method类型,GET、POST、PUT、DELETE等。

    2.consumes, produces.

    consumes:指定处理请求的提交内容类型(Content-Type),例如application/json,text/html;

    produces:指定返回的内容类型,仅当request请求头中的(Accept)类型中包含该指定类型才返回;

    3.params, headers.

    params:指定request中必须包含某些参数值才让该方法处理。

    headers:指定request中必须包含某些指定的header值,才能让该方法处理请求。

    handler method参数绑定常用的注解,根据他们处理的request的不同内容部分分为四类:

    A:处理request uri部分的注解:@PathVariable;

    B:处理request header部分的注解:@RequestHeader, @CookieValue;

    C:处理request body部分的注解:@RequestParam, @RequestBody;

    D:处理attribute类型的注解:@SessionAttributes, @ModelAttribute;

    1.@PathVariable

    当使用@RequestMapping URI template样式映射时,即someUrl/{paramId},这时的paramId可通过@PathVariable注解绑定它传过来的值到方法的参数上。

    2.@RequestHeader、@CookieValue

    @RequestHeader注解可以把Request请求header部分的值绑定到方法的参数上。

    @CookieValue可以把Request header中关于cookie的值绑定到方法的参数上。

  • 相关阅读:
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
    Penetration Test
    Distributing Ballot Boxes HDU
    Queue HDU
    Cup HDU
  • 原文地址:https://www.cnblogs.com/yili-2013/p/5424388.html
Copyright © 2011-2022 走看看