有什么办法可以在JPA Spring Boot中按列获取数据

时间:2020-07-28 22:30:16

标签: java mysql spring spring-boot jpa

这是我的控制器代码

@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]类型转换为[值'newcustomer'的java.lang.Integer];嵌套异常为java.lang.NumberFormatException:对于输入字符串:“ newcustomer”“}

在http:// localhost:8080 / customerWasteRequests / newcustomer

1 个答案:

答案 0 :(得分:0)

“无法将类型'newcustomer'的类型[java.lang.String]转换为[java.lang.Integer]

您进入实体customer的财产CustomerWasteRequest是否具有类型Integer而不是String