我想发送由用户传递给邮递员的arraylist(java)对象和其他参数。
这是我的控制器代码
@PostMapping(path = "/listEmpPaidSalariesPaged", produces = "application/json")
public List<EmployeeSalaryPayment> listEmpPaidSalariesPaged
(long SID, Collection<Student> student, String orderBy,
int limit, int offset)
我知道您可以将RAW数据和JSON用于对象和x-www-form-urlencoded作为参数,但是如何将它们一起发送?
您可以使用@RequestBody和@RequestParam批注,例如:
@PostMapping(path = "/listEmpPaidSalariesPaged", produces = "application/json")
public List<EmployeeSalaryPayment> listEmpPaidSalariesPaged(@RequestBody StudentRequestModel studentRequestModel, @RequestParam(value = "orderBy", defaultValue = "descending") String orderBy, @RequestParam(value = "limit", defaultValue = "25") int limit, @RequestParam(value = "offset", defaultValue = "0") int offset) {
// controller code
}
@@ RequestBody会自动将HttpRequest主体(邮递员的原始JSON)反序列化为Java对象(StudentRequestModel)。@RequestParam将提取您的查询参数(例如,在邮递员中,您可以对/ listEmpPaidSalariesPaged?orderBy = ascending进行POST)到定义的变量中。当然,您可以在邮递员中同时进行这两个操作。