SpringBoot @RequestParam、@PathVaribale、@RequestBody實(shí)戰(zhàn)案例
實(shí)例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 +’}’; }}
實(shí)例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.*;/** * 測(cè)試注解及調(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實(shí)戰(zhàn)案例的文章就介紹到這了,更多相關(guān)SpringBoot @RequestParam、@PathVaribale、@RequestBody內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 如何利用python操作注冊(cè)表2. 使用Hangfire+.NET 6實(shí)現(xiàn)定時(shí)任務(wù)管理(推薦)3. Xml簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理4. jsp文件下載功能實(shí)現(xiàn)代碼5. 詳解瀏覽器的緩存機(jī)制6. ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享7. xml中的空格之完全解說(shuō)8. 如何在jsp界面中插入圖片9. phpstudy apache開(kāi)啟ssi使用詳解10. JSP之表單提交get和post的區(qū)別詳解及實(shí)例
