SpringBoot請求參數(shù)相關(guān)注解說明小結(jié)
一、@PathVariable
1.作用
映射 url 路徑中的變量
2.使用方法
@RestController
public class BookController {
@GetMapping("/book/{id}")
public Integer getBook(@PathVariable("id") Integer id) {
// 打印參數(shù)
System.out.println(id);
return id;
}
}3.測試結(jié)果

二、@RequestHeader
1.作用
獲取請求頭中的參數(shù)
2.使用方法
@RestController
public class BookController {
@GetMapping("/ua")
public String getUA(@RequestHeader("User-Agent") String userAgent) {
// 打印參數(shù)
System.out.println(userAgent);
return userAgent;
}
}
3.測試結(jié)果

三、@RequestParam
1.作用
獲取url的參數(shù)
2.使用方法
@RestController
public class BookController {
@GetMapping("/book")
public Integer getBook2(@RequestParam("id") Integer id) {
// 打印參數(shù)
System.out.println(id);
return id;
}
}3.測試結(jié)果

三、@CookieValue
1.作用
獲取Cookie中的值
2.使用方法
@RestController
public class BookController {
@GetMapping("/cookie_value")
public String getCV(@CookieValue("ruid") String ruid) {
// 打印參數(shù)
System.out.println(ruid);
return ruid;
}
}
3.測試結(jié)果

四、@RequestBody
1.作用
獲取 post 請求體
2.使用方法
@RestController
public class BookController {
@PostMapping("/book")
public Book saveBook(@RequestBody Book book) {
// 打印參數(shù)
System.out.println(book);
return book;
}
}3.測試結(jié)果

到此這篇關(guān)于SpringBoot請求參數(shù)相關(guān)注解說明的文章就介紹到這了,更多相關(guān)SpringBoot請求參數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- spring?boot常見get?、post請求參數(shù)處理、參數(shù)注解校驗(yàn)、參數(shù)自定義注解校驗(yàn)問題解析
- SpringBoot使用AOP與注解實(shí)現(xiàn)請求參數(shù)自動(dòng)填充流程詳解
- SpringBoot請求處理之常用參數(shù)注解介紹與源碼分析
- SpringBoot常見get/post請求參數(shù)處理、參數(shù)注解校驗(yàn)及參數(shù)自定義注解校驗(yàn)詳解
- SpringBoot 攔截器和自定義注解判斷請求是否合法
- SpringBoot http請求注解@RestController原理解析
- spring boot接收請求常用注解示例詳解
相關(guān)文章
Java?實(shí)戰(zhàn)范例之校園二手市場系統(tǒng)的實(shí)現(xiàn)
讀萬卷書不如行萬里路,只學(xué)書上的理論是遠(yuǎn)遠(yuǎn)不夠的,只有在實(shí)戰(zhàn)中才能獲得能力的提升,本篇文章手把手帶你用java+SSM+mysql+maven+tomcat實(shí)現(xiàn)一個(gè)校園二手市場系統(tǒng),大家可以在過程中查缺補(bǔ)漏,提升水平2021-11-11
springboot使用AOP+反射實(shí)現(xiàn)Excel數(shù)據(jù)的讀取
本文主要介紹了springboot使用AOP+反射實(shí)現(xiàn)Excel數(shù)據(jù)的讀取,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-01-01
SpringBoot利用自定義json序列化器實(shí)現(xiàn)敏感字段數(shù)據(jù)脫敏詳解
這篇文章主要介紹了SpringBoot利用自定義json序列化器實(shí)現(xiàn)敏感字段數(shù)據(jù)脫敏詳解,因?yàn)榘咐a用到了hutool提供的DesensitizedUtil數(shù)據(jù)脫敏工具類,這里要引入hutool的依賴,如果你需要自定義 數(shù)據(jù)脫敏的邏輯,可以不引入這個(gè)依賴,需要的朋友可以參考下2024-01-01
Spring Boot 簡單使用EhCache緩存框架的方法
本篇文章主要介紹了Spring Boot 簡單使用EhCache緩存框架的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07
SpringBoot通過自定義注解實(shí)現(xiàn)參數(shù)校驗(yàn)
實(shí)現(xiàn)參數(shù)校驗(yàn)說實(shí)話方式還挺多,個(gè)人使用過直接在Controller代碼里面寫、AOP+自定義注解、ConstraintValidator。本文主要和大家講的是ConstraintValidator實(shí)現(xiàn),感興趣的可以了解一下2022-12-12
mybatis?<foreach>標(biāo)簽動(dòng)態(tài)增刪改查方式
這篇文章主要介紹了mybatis?<foreach>標(biāo)簽動(dòng)態(tài)增刪改查方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-03-03

