RequestMapping註解詳解

2021-09-27 12:03:34 字數 1210 閱讀 3682

method:  指定請求的method型別, get、post、put、delete等;

produces:    指定返回的內容型別,僅當request請求頭中的(accept)型別中包含該指定型別才返回;

params: 指定request中必須包含某些引數值是,才讓該方法處理。

headers: 指定request中必須包含某些指定的header值,才能讓該方法處理請求。

@controller

value的uri值為以下三類:

a) 可以指定為普通的具體值;

b)  可以指定為含有某變數的一類值(uri template patterns with path variables);

c) 可以指定為含正規表示式的一類值( uri template patterns with regular expressions);

example b)

publicstring findowner(@pathvariable string ownerid, model model)

example c)

public voidhandle(@pathvariable string version, @pathvariable string extension) }

cousumes的樣例:

@controller

public voidaddpet(@requestbody pet pet, model model)

produces的樣例:

@controller

@responsebody

publicpet getpet(@pathvariable string petid, model model)

params的樣例:

@controller

public classrelativepathuritemplatecontroller {

僅處理請求中包含了名為「myparam」,值為「myvalue」的請求;

headers的樣例:

@controller

public classrelativepathuritemplatecontroller {

僅處理request的header中包含了指定「refer」請求頭和對應值為「」的請求;

RequestMapping註解用法

1.標註在方法上 作為請求處理方法在程式接收到對應的url請求時被呼叫 package com.itheima.controller import org.springframework.stereotype.controller controller public class firstcontr...

RequestMapping使用須知

即 也可以定義方法上 一般來說,類級別的註解負責將乙個特定 或符合某種模式 的請求 路徑對映到乙個控制器上,同時通過方法級別的註解來細化對映,即 根據特定的http請求方法 get post 方法等 http請求中是 否攜帶特定引數等條件,將請求對映到匹配的方法上 具體配置方法 1 對映單個url ...

RequestMapping註解詳解

method 指定請求的method型別,get post put delete等 produces 指定返回的內容型別,僅當request請求頭中的 accept 型別中包含該指定型別才返回 params 指定request中必須包含某些引數值是,才讓該方法處理。headers 指定request...