【问题标题】:Is there any way to get data by column in jpa spring boot有没有办法在jpa spring boot中按列获取数据
【发布时间】: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。后端的模型呢?属性 customerinteger 还是 String

标签: java mysql spring spring-boot jpa


【解决方案1】:

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

您的属性customer 到实体CustomerWasteRequest 中是否具有类型Integer 而不是String

【讨论】:

  • 是的,有一个整数类型而不是字符串。非常感谢您显示错误
猜你喜欢
  • 2021-02-09
  • 2019-10-03
  • 2016-08-08
  • 2023-03-16
  • 1970-01-01
  • 2016-08-20
  • 1970-01-01
  • 1970-01-01
  • 2017-11-06
相关资源
最近更新 更多