Spring 带参数的Get方法
我试图获取Spring 带参数的Get方法,spring,spring-boot,spring-data-jpa,Spring,Spring Boot,Spring Data Jpa,我试图获取条码变量,而数量变量为0或!=。如选择数量为0的条形码或选择数量为0的条形码。我花了一整天的时间,但我不知道该怎么做。请帮帮我 @GetMapping(path = "/barcode/{barcode}") public List<User> findd(@PathVariable("barcode") String barcode, @RequestParam Int
条码
变量,而数量
变量为0或!=。如选择数量为0的条形码或选择数量为0的条形码。我花了一整天的时间,但我不知道该怎么做。请帮帮我
@GetMapping(path = "/barcode/{barcode}")
public List<User> findd(@PathVariable("barcode") String barcode,
@RequestParam Integer qty) {
return repository.findByQty(qty);
}
@GetMapping(path=“/barcode/{barcode}”)
公共列表findd(@PathVariable(“条形码”)字符串条形码,
@RequestParam(整数数量){
返回存储库。findByQty(数量);
}
public interface UserRepository扩展了JpaRepository{
用户findByBarcode(字符串条形码);
列出findByQty(整数数量);
}
您只是按数量获取结果,这是绝对错误的。 有多个产品的数量为0。 因此,您必须同时传递数量和条形码才能获取结果。 例如: 从表_name中选择条形码,其中条形码=666,数量=0 在控制器方法级别,可以轻松地以传递数量的相同方式传递路径变量
public interface UserRepository extends JpaRepository<User,Integer> {
User findByBarcode(String barcode);
List <User> findByQty(int qty);
}