SpringBoot,Controller 注解

SpringBoot,Controller 注解

  • @RequestMapping("/ping")

@PathVariable

    @RequestMapping(value="/{id}", method=RequestMethod.GET)
    public List> getUser(@PathVariable Integer id) {
        return userService.getUserById(id);
    }

    @RequestMapping(value="/{uid}", method=RequestMethod.GET)
    public List> getUser(@PathVariable("uid") Integer id) {
        return userService.getUserById(id);
    }

@RequestParam

  @RequestMapping(value="", method=RequestMethod.POST)
   public String postUser(@RequestParam(value="phoneNum", required=true) String phoneNum ) String userName) {
        userService.create(phoneNum, userName);
        return "success";
    }

@RequestBody

    @RequestMapping(value = "/testUser", method = RequestMethod.POST)
	public String testUser(@RequestBody User user){
        System.out.print(user.getAge());
        return "success";
    }
	
	# 参数
	{"id":1,"user":"pkxutao","name":"name","age":18}

你可能感兴趣的:(Spring,Boot)