为了账号安全,请及时绑定邮箱和手机立即绑定

定义返回列表的 REST 端点

定义返回列表的 REST 端点

慕码人2483693 2021-10-28 14:40:53
如何从控制器类返回列表?我目前的代码:@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方法:@Transactionalpublic 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)
查看完整描述

2 回答

?
牧羊人nacy

TA贡献1862条经验 获得超7个赞

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


@PostMapping(value = Endpoint.RRESOURCE_customer_ID)

public List<CustomerDto> getLocationsByLocationIds(@RequestBody List<Long> ids) {

    return customerService.findcustomerIds(ids);

}

请注意,您不能同时拥有@RequestBody和@RequestParam。该字段是任一的HTTP请求体或HTTP请求参数。


查看完整回答
反对 回复 2021-10-28
?
陪伴而非守候

TA贡献1757条经验 获得超8个赞

您必须在 ReponseEntity 类中返回“customerDto”列表


@PostMapping(value = Endpoint.RRESOURCE_customer_ID)

@ResponseBody

public ResponseEntity<List<customerDto> > getLocationsByLocationIds(@RequestParam List<Long> ids) {

      List<customerDto> customerListDto = customerService.findcustomerIds(ids);

      return ResponseEntity.ok(customerListDto);

}


查看完整回答
反对 回复 2021-10-28
  • 2 回答
  • 0 关注
  • 116 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信