我有一个表客户和 2 列 customer_id 和 customer_name。我想用json发送id列表请求并返回相应的客户名称。但我无法处理 dto 对象和控制器服务架构。
输入dto:
public class CustomerSearchDto extends BaseDto {
@ApiModelProperty(
example = "1",
value = "Customer Id",
required = true,
dataType = "Long"
)
private Long id;
}
输出到:
public class CustomerDto extends BaseDto {
private Long id;
private String name;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
控制器类:
@ApiOperation(
value = "Return Customer",
response = Customer.class
)
@PostMapping(value = Endpoint.RRESOURCE_CUSTOMER_GROUP_BY_ID)
public ResponseEntity<CustomerDto> getCustomersById(@RequestBody @Validated CustomerSearchDto CustomerSearchDto) {
CustomerDto CustomerDto = new CustomerDto;
List<CustomerDto> CustomerDtoList = CustomerService.findCustomerByIds(ids);
return ResponseEntity.ok(CustomerDto);
}
服务类方法:
@Transactional
public List<CustomerDto> findCustomerByIds(List<Long> customerIds) {
List<Customer> customerList = repository.findCustomerById(CustomerIds);
return mapper.mapAsList(CustomerList, CustomerDto.class);
}
控制器类中有一些错误。而且我不确定我是否应该为输入和输出定义不同的 dto 类?
一只甜甜圈
12345678_0001
相关分类