Spring Boot笔记-接收参数的3种情况

如下代码:

@RestController
public class MyController {

    @GetMapping("/test1")
    public MyResponse test1(MyRequest myRequest){

        MyResponse myResponse = new MyResponse();
        myResponse.setCode(myRequest.getCode());
        myResponse.setMsg(myRequest.getMsg());
        return myResponse;
    }

    @GetMapping("/test2")
    public MyResponse test2(Integer code, String msg){

        MyResponse myResponse = new MyResponse();
        myResponse.setCode(code);
        myResponse.setMsg(msg);
        return myResponse;
    }

    @GetMapping("/test3")
    public MyResponse test3(@RequestParam("code") Integer code, @RequestParam("msg") String msg){

        MyResponse myResponse = new MyResponse();
        myResponse.setCode(code);
        myResponse.setMsg(msg);
        return myResponse;
    }
}

这里可以直接搞个对象,这样spring也能直接映射,如下运行截图

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页