Learning record, the rear end of the data received in several ways json
1. Direct receive or received by HttpServletRequest
public void test(String userid, HttpServletRequest request) {
String userName = request.getParameter("username");
System.out.println("-"+userid+"-"+username+"-");
}
2.使用@RequestParam
// Data Name same
public void Test (STR @RequestParam String) {}
// different data name
// defaultValue set default values for the default null
// parameters are required to be provided, the default is true, must pass
public void test (@ RequestParam (value = "STR", defaultValue = "defaultStr", required to false =) String Str) {}
3. use @RequestVariable
@RequestMapping(value="/user/{userid}/{username}")
public void test(@PathVariable(value="userid")int userId, @PathVariable(value="username")String userName) {}
4.使用@RequestBody
// @ RequestBody for post request, can not be used to get request
public void Test (@RequestBody the User User) {}
public void Test (@RequestBody the Map <String, Object> Map) {}
5. The use @ModelAttribute
@GetMapping combination annotation is @RequestMapping (method = RequestMethod.GET) Abbreviation
@ PostMapping, similar @ PutMapping, @ DeleteMapping, @ PatchMapping
@RestController equivalent @ ResponseBody + @ Controller used in combination
---------------------
Author: BattleCall30
Source: CSDN
Original: https: //blog.csdn.net/baidu_38622301 / article / details / 81430293
copyright: This article is a blogger original article, reproduced, please attach Bowen link!