SpringBoot Controller

来源:互联网 发布:js断点调试 编辑:程序博客网 时间:2024/06/03 18:09

@Controller处理HTTP请求

@RestController =  @Controller + @ResponseBody  处理Rest请求

@RequestMapping 配置URL映射



1、获取请求参数的两种方式


@RestControllerpublic class HelloController {    @Value("${cupSize}")    private String cupSize;    @Value("${age}")    private Integer age;    @Autowired    private GirlProperties girlProperties;        //请求形式1    //  localhost:8082/hello/12    @RequestMapping(value = "/hello/{id}",method = RequestMethod.GET)    public String say(@PathVariable("id") Integer id)    {        return "id:" + id;    }    //请求形式2    //localhost:8082/hello?hi=12    //@RequestMapping(value = "/hi",method = RequestMethod.GET)    @GetMapping(value = {"/hi","hello"})    public String hi(@RequestParam(value = "id",required = false,defaultValue = "0") Integer id)    {        return "id:" + id;    }}


required = false,defaultValue = "0"
表示不必须,缺省值为0




原创粉丝点击