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.*;/** * 測試注解及調(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. ASP新手必備的基礎(chǔ)知識(shí)2. ASP.NET Core按用戶等級(jí)授權(quán)的方法3. vue-electron中修改表格內(nèi)容并修改樣式4. .NET 中配置從xml轉(zhuǎn)向json方法示例詳解5. 推薦一個(gè)好看Table表格的css樣式代碼詳解6. ASP常用日期格式化函數(shù) FormatDate()7. 利用FastReport傳遞圖片參數(shù)在報(bào)表上展示簽名信息的實(shí)現(xiàn)方法8. phpstudy apache開啟ssi使用詳解9. HTML中的XML數(shù)據(jù)島記錄編輯與添加10. 微信小程序?qū)崿F(xiàn)商品分類頁過程結(jié)束
