SpringBoot注解

@PathVariable:接收请求路径中占位符的值

img

@RequestParam:将请求参数绑定到controller的方法参数上

/**
     * 接收普通请求参数
     * http://localhost:8080/hello/show16?name=linuxsir
     * url参数中的name必须要和@RequestParam("name")一致
     * @return
     */
    @RequestMapping("show16")
    public ModelAndView test16(@RequestParam("name")String name){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("hello2");
        mv.addObject("msg", "接收普通的请求参数:" + name);
        return mv;
    }

@RequestBody:主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的)。使用@RequestBody接收数据时,前端不能使用GET方式提交数据,而是用POST方式进行提交。在后端的同一个接收方法里,@RequestBody与@RequestParam()可以同时使用,@RequestBody最多只能有一个,而@RequestParam()可以有多个

posted @ 2021-06-07 21:23  又又又8  阅读(34)  评论(0编辑  收藏  举报