Spring boot 如何基于字符串参数在jpa存储库中执行sql查询

Spring boot 如何基于字符串参数在jpa存储库中执行sql查询,spring-boot,Spring Boot,我想显示基于不同参数的表格数据,如价格范围和类别 @实体 公共类项目{ @身份证 @生成值 私人长id; 私有字符串名称; 私人双价; 私有字符串类别; 公共项目(){ 超级(); } 项目(字符串名称、字符串类别){ 超级(); this.name=名称; this.category=类别; } 公共项目(长id、字符串名称、双倍价格、字符串类别){ 超级(); this.id=id; this.name=名称; 这个价格=价格; 这个。类别=类别; } 公共长getId(){ 返回id; }

我想显示基于不同参数的表格数据,如价格范围和类别

@实体
公共类项目{
@身份证
@生成值
私人长id;
私有字符串名称;
私人双价;
私有字符串类别;
公共项目(){
超级();
}
项目(字符串名称、字符串类别){
超级();
this.name=名称;
this.category=类别;
}
公共项目(长id、字符串名称、双倍价格、字符串类别){
超级();
this.id=id;
this.name=名称;
这个价格=价格;
这个。类别=类别;
}
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
公共字符串getName(){
返回名称;
}
公共void集合名(字符串名){
this.name=名称;
}
公开双价{
退货价格;
}
公共定价(双倍价格){
这个价格=价格;
}
公共字符串getCategory(){
退货类别;
}
公共无效集合类别(字符串类别){
this.category=类别;
}
}
@存储库
公共接口ItemRepository扩展了JpaRepository{
}
我想使用postman显示基于类别和价格范围的表数据。
由于使用long as参数,我只能根据id号检索商品。

从您的问题中我了解到,您需要有基于类别和价格而不是使用id返回数据的方法

@Repository
public interface ItemRepository extends JpaRepository<Item, Long >{

List<Item> findByCategory(String category);
List<Item> findByPrice(Double price);

}
@存储库
公共接口ItemRepository扩展了JpaRepository{
列表findByCategory(字符串类别);
清单发现价格(双倍价格);
}
您也可以使用SpringJPA查询方法为其提供默认实现

欲了解更多信息,请阅读

另一个例子:
列出找到的ByCategoryandPrice(字符串类别,双倍价格);
 List<Item> findByCategoryAndPrice(String category,Double price);