美文网首页
2018-04-30

2018-04-30

作者: JavaLearner | 来源:发表于2018-04-30 22:09 被阅读0次

    @PathVariable获取url中的数据
    @RequestParam获取请求参数的值
    @GetMaping组合注解,是@RequestMapping(method=GET)的缩写

    @RestController
    public class Controller {
        @RequestMapping(method = GET, value="/hello/{id}/{name}")
        public String sayHello(@PathVariable("id")Integer id, @PathVariable("name") String name) {
            return "id:" + id + " name:" + name + "\n";
        }
    
        @GetMapping("/helloworld")
        public String helloWorld() {
            return "helloWorld";
        }
    
        @RequestMapping(method=GET, value="/greeting")
        public String greetingFunc(@RequestParam(value="name", defaultValue = "World") String name) {
           return "name " + name;
        }
    }
    

    相关文章

      网友评论

          本文标题:2018-04-30

          本文链接:https://www.haomeiwen.com/subject/cvptrftx.html