您好,登錄后才能下訂單哦!
本篇文章給大家分享的是有關SpringBoot項目中如何使用@PathVaribale、@RequestBody和@RequestParam,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。
實例User
package com.iflytek.odeon.shipper.model.rx; import io.swagger.annotations.ApiModelProperty; public class Student { @ApiModelProperty(value = "名稱", example = "zhangsan", required = true) private String name; private Integer call; public Student() { } public Student(String name, Integer call) { this.name = name; this.call = call; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getCall() { return call; } public void setCall(Integer call) { this.call = call; } @Override public String toString() { return "Student{" + "name='" + name + '\'' + ", call=" + call + '}'; } }
實例Controller
package com.iflytek.odeon.shipper.controller; import com.iflytek.odeon.shipper.model.rx.Student; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; /** * 測試注解及調試功能API */ @RestController @RequestMapping("/v1") public class SampleController { @PostMapping("/hi") public Student hi(@RequestBody() Student student) { return new Student(student.getName(), student.getCall()); } @PostMapping("/hello") public Student hello(@RequestParam(value = "name") String name, @RequestParam(value = "call") Integer call) { Student stuResponse = new Student(); stuResponse.setName(name + "call"); stuResponse.setCall(call); return stuResponse; } @GetMapping("/hello/{id}") public Integer getUrl(@PathVariable(value = "id") Integer id) { return id; } }
效果
body
parme key value
pathvar
/{id}
以上就是SpringBoot項目中如何使用@PathVaribale、@RequestBody和@RequestParam,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。