gpt4 book ai didi

java - 定义返回列表的 REST 端点

转载 作者:行者123 更新时间:2023-12-02 10:44:44 24 4
gpt4 key购买 nike

如何从 Controller 类返回列表?

我当前的代码:

@PostMapping(value = Endpoint.RRESOURCE_customer_ID)
public ResponseEntity<customerDto> getLocationsByLocationIds(@RequestBody @Validated @RequestParam(name = "ids", required = true) List<Long> ids) {
List<customerDto> customerListDto = customerService.findcustomerIds(ids);
return ResponseEntity.ok(customerListDto);
}

我收到的错误:

Error:(51, 41) java: incompatible types: inference variable T has incompatible bounds
equality constraints: com.testclass.cust.common.dto.output.CustomerDto
lower bounds: java.util.List<com.customer.common.dto.output.CustomerDto>

findcustomerIds 方法:

@Transactional
public List<customerDto> findcustomerIds(List<Long> customerIds) {
List<customer> customerList = repository.findAll(customerIds);
return mapper.mapAsList(customerList, customerDto.class);
}

我不确定下一个定义。

public ResponseEntity<customerDto> getLocationsByLocationIds(@RequestBody @Validated @RequestParam(name ="ids", required = true) List<Long> ids)

最佳答案

您应该按如下方式定义端点:

@PostMapping(value = Endpoint.RRESOURCE_customer_ID)
public List<CustomerDto> getLocationsByLocationIds(@RequestBody List<Long> ids) {
return customerService.findcustomerIds(ids);
}

请注意,同一字段中不能同时使用 @RequestBody@RequestParam。该字段是 HTTP 请求正文或 HTTP 请求参数。

关于java - 定义返回列表的 REST 端点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52665272/

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