135-如何实现result风格

  @RequestMapping(value = "/user/{id}") //注意id的默认值是1,不是0也不是null;传参时:localhost:8080/user/9999
    public Object user1(@PathVariable("id") Integer id) {
        return "id="+id;
    }
  
  //为了避免以下的情况,我们url冲突的情况,我们一般使用不同的注解,或者在添加前缀路径,  //要不然会出现: "error": "Method Not Allowed",错误
    @GetMapping(value = "/user/{id}/{name}")
    public Object user2(@PathVariable("id") Integer id,
                        @PathVariable("name") String name) {
        return "id="+id+",name="+name;
    }

    @PostMapping(value = "/user/{name}/{id}")
    public Object user3(@PathVariable("name") String name,
                        @PathVariable("id") Integer id) {
        return "name="+name+",id="+id;
    }

 

来源:https://www.cnblogs.com/pogusanqian/p/12747575.html