zoukankan      html  css  js  c++  java
  • Spring 注解学习

        @GetMapping(value = "/hello/{id}")//需要获取Url=localhost:8080/hello/id中的id值
        public String sayHello(@PathVariable("id") Integer id){
            return "id:"+id;
        }
        @GetMapping(value="/hello/{id}/{name}")//需要在url有多个参数需要获取
        public String sayHello(@PathVariable("id") Integer id,@PathVariable("name") String name){
            return "id:"+id+" name:"+name;
        }
        @GetMapping(value="/hello")//localhost:8080/hello?id=98,@RequestParam 获取请求参数的值
        public String hello(@RequestParam("id") Integer id,@RequestParam("access_token")String accessToken){
            return "id:"+id+"   accessToken:"+accessToken;
        }
        @GetMapping(value="/hello1")//我们在浏览器中输入地址:localhost:8080/hello ,即不输入id参数,则报错  Required Integer parameter 'id' is not present
        //可以添加默认参数
        public String hello1(@RequestParam(value = "id",required = false,defaultValue = "1") Integer id,@RequestParam("access_token")String accessToken){
            return "id:"+id+"   accessToken:"+accessToken;
        }
  • 相关阅读:
    JS——祝愿墙
    JS——模拟百度搜索
    JS——选择水果
    html——快捷键
    JS——百度背景图
    JS——stye属性
    JS——高级各行换色
    html——细线表格
    LeetCode初级算法(数组)解答
    Python网络爬虫(四)
  • 原文地址:https://www.cnblogs.com/huanghuanghui/p/10608795.html
Copyright © 2011-2022 走看看