gpt4 book ai didi

spring - 如何在Spring Boot API中通过requestbody获取对象列表

转载 作者:行者123 更新时间:2023-12-04 11:21:51 24 4
gpt4 key购买 nike

通过 Controller 中的@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){

最佳答案

下面对我有用

@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);
}
您需要在类(class)路径中使用 jackson
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.6.0</version>
</dependency>
杰森(Json)是
[{"sort":"10-20-30","account":"1234"},{"sort":"10-20-30","account":"1234"}]

关于spring - 如何在Spring Boot API中通过requestbody获取对象列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35266289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com