您的位置:首页 > 编程语言 > Java开发

SpringBoot Controller

2017-10-16 20:38 344 查看
@Controller处理HTTP请求@RestController =  @Controller + @ResponseBody  处理Rest请求@RequestMapping 配置URL映射1、获取请求参数的两种方式@RestControllerpublic class HelloController {@Value("${cupSize}")private String cupSize;@Value("${age}")private Integer age;@Autowiredprivate 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

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息