當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Springboot 请求数据
生活随笔
收集整理的這篇文章主要介紹了
Springboot 请求数据
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
請(qǐng)求方式
get
請(qǐng)求時(shí)在瀏覽器中輸入: localhost:8080/hello?name=zhangsan&age=18
這個(gè)實(shí)體類里應(yīng)有g(shù)et set方法,要不返回為空
請(qǐng)求時(shí)在瀏覽器中輸入: localhost:8080/hello3/77?name=zhangsan&age=18
@RequestMapping("/hello3/{id}") public String say3(@PathVariable(value="id") Integer id,@RequestParam(value="name") String name,@RequestParam(value="age", required=false, defaultValue="1000") String age){return "id: " + id + ", name: " + name + ", age: " + age; }post
與get區(qū)別在于應(yīng)在實(shí)體類上加@RequestBody注解,原因未知
post發(fā)送請(qǐng)求用x-www-form-urlencoded格式可以傳遞參數(shù),用form-data只會(huì)有默認(rèn)值,具體區(qū)別請(qǐng)參考 https://blog.csdn.net/u013827143/article/details/86222486
@PostMapping("/hello7") public String say7(@RequestParam(value="name") String name,@RequestParam(value="age") String age) {String result = "name: " + name + ", age:" + age;System.out.println(result);return result; }http請(qǐng)求格式
| 狀態(tài)行(請(qǐng)求方法+請(qǐng)求協(xié)議) | GET /test.html HTTP/1.1 |
| 請(qǐng)求頭 | Accept: image/gif |
| 請(qǐng)求體 |
| application/x-www-form-urlencoded | |
| multipart/form-data | |
| application/json | |
| text/xml |
總結(jié)
以上是生活随笔為你收集整理的Springboot 请求数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 日志清洗
- 下一篇: Recom Recall