SpringBoot @RequestParam、@PathVaribale、@RequestBody實戰(zhàn)案例
實例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.*;
/**
* 測試注解及調(diào)試功能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}

到此這篇關(guān)于SpringBoot @RequestParam、@PathVaribale、@RequestBody實戰(zhàn)案例的文章就介紹到這了,更多相關(guān)SpringBoot @RequestParam、@PathVaribale、@RequestBody內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java Mybatis中的 ${ } 和 #{ }的區(qū)別使用詳解
這篇文章主要介紹了Mybatis中的 ${ } 和 #{ }的區(qū)別使用詳解,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-07-07
SWT(JFace)體驗之ApplicationWindow
SWT(JFace)體驗之ApplicationWindow2009-06-06
Java Web使用Html5 FormData實現(xiàn)多文件上傳功能
這篇文章主要介紹了Java Web使用Html5 FormData實現(xiàn)多文件上傳功能,需要的朋友可以參考下2017-07-07
Java?BasePooledObjectFactory?對象池化技術(shù)的使用
這篇文章主要介紹了Java?BasePooledObjectFactory?對象池化技術(shù),本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-04-04
Java封裝實現(xiàn)自適應的單位轉(zhuǎn)換工具類
這篇文章主要為大家詳細介紹了如何使用Java封裝實現(xiàn)一個自適應的單位轉(zhuǎn)換工具類,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2025-03-03
Springboot jdbctemplate整合實現(xiàn)步驟解析
這篇文章主要介紹了Springboot jdbctemplate整合實現(xiàn)步驟解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-08-08
基于spring boot 2和shiro實現(xiàn)身份驗證案例
這篇文章主要介紹了基于spring boot 2和shiro實現(xiàn)身份驗證案例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-04-04
使用Spring的FactoryBean創(chuàng)建和獲取Bean對象方式
這篇文章主要介紹了使用Spring的FactoryBean創(chuàng)建和獲取Bean對象方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2025-03-03

