日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Springboot 请求数据

發(fā)布時(shí)間:2024/10/8 javascript 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Springboot 请求数据 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

請(qǐng)求方式

get
  • 用RequestMapping
  • @RequestMapping("/hello") // 默認(rèn)為get方式,或者可以寫成@RequestMapping(value="/hello", method.RequestMethod.GET) public String say() {return "hello"; }
  • 用GetMapping
  • @GetMapping("/hello1") public String say1() {return "hello"; }
  • 有參方法
    請(qǐng)求時(shí)在瀏覽器中輸入: localhost:8080/hello?name=zhangsan&age=18
    這個(gè)實(shí)體類里應(yīng)有g(shù)et set方法,要不返回為空
  • @RequestMapping("/hello2") public String say2(Person person) {return person.toString(); }public class Person {private String name;private int age;public String getName() {return name;}public int getAge() {return age;}public void setName(String name) {this.name = name;}public void setAge(int age) {this.age = age;}public String toString() {return "name:" + name + ";age:" + age;} }

    請(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
  • 用RequestMapping
  • @RequestMapping("/hello4", method=RequestMethod.POST) public String say4() {return "hello 4"; }
  • 用PostMapping
  • @PostMapping("/hello5") public String say5() {return "hello 5"; }
  • 有參方法,模擬post請(qǐng)求需要下載postman等插件進(jìn)行模擬
    與get區(qū)別在于應(yīng)在實(shí)體類上加@RequestBody注解,原因未知
  • @PostMapping("/hello6") public String say6(@RequestBody Person person) {System.out.println(person.toString());return person.toString(); }

    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)求格式

    請(qǐng)求部分請(qǐng)求內(nèi)容
    狀態(tài)行(請(qǐng)求方法+請(qǐng)求協(xié)議)GET /test.html HTTP/1.1
    請(qǐng)求頭Accept: image/gif
    請(qǐng)求體
    POST提交數(shù)據(jù)方式區(qū)別
    application/x-www-form-urlencoded
    multipart/form-data
    application/json
    text/xml

    總結(jié)

    以上是生活随笔為你收集整理的Springboot 请求数据的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。