通过控制器中的@RequestBody
获取对象列表,并处理list
中的每个对象以执行业务逻辑。
我试过这个但没有工作
@RequestMapping(value="/updateservicetype", method=RequestMethod.POST,produces="application/json")
public @ResponseBody ServiceTypesMessage updateServiceType(@RequestBody List<BarberServiceType> serviceTypes,final HttpServletResponse response){
也试过以下:
@RequestMapping(value="/updateservicetype", method=RequestMethod.POST,produces="application/json")
public @ResponseBody ServiceTypesMessage updateServiceType(@RequestBody BarberServiceType[] serviceTypes,final HttpServletResponse response){
答案 0 :(得分:5)
以下适用于我
@RequestMapping(value = "/payments", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody List<Payment> batchCreate(@RequestBody List<Payment> payments) {
return paymentService.create(payments);
}
你需要杰克逊在课程路径
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
Json in put是
[{"sort":"10-20-30","account":"1234"},{"sort":"10-20-30","account":"1234"}]