Problem description
SpringBoot interface uses Post request to receive the front-end JSON data and writes multiple parameters
No matter how you write the data you get, it is null
$.ajax({ url: "login4", param: ({ "name": "name", "age": 10 }), type: "post", dataType: "json", success: function (data) { }, error: function (data) { } });
@PostMapping("login4") public void login4(String name, Integer age){ ("login3"); (name + " -- " + age); }
Cause analysis
When receiving JSON data, the POST request cannot automatically fill the data using simple types (Integer, String), etc.
Must be encapsulated as entity classes or receive using Map
In addition, when receiving using Map, you must also indicate generics.
Solution
Similar to the following method
Encapsulate an entity class (the attribute name of the entity class must correspond to the front-end request parameter) or use Map<String,Object>
You can get it by adding the RequestBody annotation before
@RequestMapping("/saveGrAuditLog") public void auditUploads(@RequestBody AuditRequestEntity auditRequestEntity, HttpServletRequest request){ WriteLogParam writeLogParam = new WriteLogParam(); (()); (()); (()); (()); (()); ("******params >> "+ (writeLogParam)); (request,(),(),(),writeLogParam); }
Summarize
The above is personal experience. I hope you can give you a reference and I hope you can support me more.