【发布时间】:2020-07-28 22:30:16
【问题描述】:
这是我的控制器代码
@GetMapping("/customerWasteRequest/{customer}")
public List<CustomerWasteRequest> getCustomerWasteRequest(@PathVariable String customer) {
return service.fetchWasteRequestByCustomer(customer);
}
这是我的服务代码
public class CustomerWasteRequestService{
@Autowired
private CustomerWasteRequestRepository repo;
public List<CustomerWasteRequest> fetchWasteRequestByCustomer(String customer) {
return repo.findByCustomer(customer);
}
}
存储库代码
@Repository
public interface CustomerWasteRequestRepository extends JpaRepository<CustomerWasteRequest, Integer> {
public List<CustomerWasteRequest> findByCustomer(String customer);
}
当我调用函数时 - getCustomerWasteRequests
private baseUrl = 'http://localhost:8080/customerWasteRequest';
getCustomerWasteRequests(customer:string) : Observable<any>{
return this.http.get(`${this.baseUrl}/${customer}`);
}
它给了我错误
{"cause":{"cause":null,"message":"对于输入字符串:"newcustomer""},"message":"从 [java.lang.String] 类型转换为 [ java.lang.Integer] for value 'newcustomer';嵌套异常是 java.lang.NumberFormatException:对于输入字符串:"newcustomer""}
在 http://localhost:8080/customerWasteRequests/newcustomer
【问题讨论】:
-
可以发一下模型类,即
CustomerWasteRequest吗? -
出口类WasteRequest { id:number;废物类型:字符串;数量:数量;日期:日期;客户:字符串;构造函数(){} }
-
这个模型似乎基于 TypeScript。后端的模型呢?属性
customer是integer还是String?
标签: java mysql spring spring-boot jpa