介绍
本篇文章给大家分享的是有关SpringBoot项目中如何使用@PathVaribale, @RequestBody和@RequestParam,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。
实例用户
包com.iflytek.odeon.shipper.model.rx; 进口io.swagger.annotations.ApiModelProperty; 公开课学生{ @ApiModelProperty(值=https://www.yisu.com/zixun/泵啤?示例=皕hangsan”,要求=true) 私人字符串名称; 私人电话整数; 公共的学生(){ } 公开学生(字符串名称,整数调用){ this.name=名称; 这一点。叫=叫; } 公共字符串getName () { 返回名称; } 公共空间setName(字符串名称){ this.name=名称; } 公共整数getCall () { 回电话; } 公共空间setCall(整数){ 这一点。叫=叫; } @Override 公共字符串toString () { 返回“学生{”+ “name=" +名称+“/? ”,电话=" +电话+ '} '; } }
实例控制器
包com.iflytek.odeon.shipper.controller; 进口com.iflytek.odeon.shipper.model.rx.Student; 进口org.springframework.stereotype.Controller; 进口org.springframework.web.bind.annotation。*;/* * *测试注解及调试功能的API */@RestController @RequestMapping (“/v1") 公开课SampleController { @PostMapping (“/hi") 公开学生嗨(@RequestBody()学生学生){ 返回新学生(student.getName (), student.getCall ()); } @PostMapping (“/hello") 公开学生你好(@RequestParam (value=https://www.yisu.com/zixun/懊帧?字符串名称,@RequestParam (value=暗饔谩?整数调用){ 学生stuResponse=new (); stuResponse。setName(名字+电话); stuResponse.setCall(电话); 返回stuResponse; } @GetMapping (“/hello/{id}”) 公共整数getUrl (@PathVariable (value=" id "的)整数id) { 返回id; } }
<>强效果强>
身体
parme键值
以上就是SpringBoot项目中如何使用@PathVaribale, @RequestBody和@RequestParam,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注行业资讯频道。