Spring 如何使用卷曲从弹簧靴积垢中计数?

Spring 如何使用卷曲从弹簧靴积垢中计数?,spring,spring-boot,count,crud,spring-data-rest,Spring,Spring Boot,Count,Crud,Spring Data Rest,我对回购有一个简单的定义: public interface StorageService extends CrudRepository<Car, Long> {} 基本上,我使用的是来自的save()和findAll()方法 如何使用curl调用count()方法,curl也在crudepository中定义(没有定义其他服务)我认为这是不可能的 在我看来(可能我错了),这是因为SpringDataREST基本上是通过HTTP方法(GET、POST等)提供rest端点,用于对资源

我对回购有一个简单的定义:

public interface StorageService extends CrudRepository<Car, Long> {}
基本上,我使用的是来自的
save()
findAll()
方法


如何使用curl调用
count()
方法,curl也在
crudepository
中定义(没有定义其他服务)

我认为这是不可能的 在我看来(可能我错了),这是因为SpringDataREST基本上是通过HTTP方法(GET、POST等)提供rest端点,用于对资源(实体)执行操作,而GET计数不是HTTP操作

但是你可以通过其他两种方式来实现这一点

  • 在Repository类中编写这样的方法

    carcountbymodel(字符串模型)

  • 这将使GET端点在/cars/search/countByModel处可用

    还是像这样

  • 这将使GET端点在/cars/search/getCount处可用

  • @查询
    工作正常。这与Spring提取所有数据源上的数据的方式相同吗?如果实体类中有一个名为
    model
    的字段,countByModel也应该可以工作。我不知道我是否理解你问题的第二部分我想数一数。不是通过过滤器。谢谢
    curl -v http://localhost:8080/cars
    curl -i -X POST -H "Content-Type:application/json" -d '{"licensePlate" : "Vegan is Moral" }' http://localhost:8080/cars
    
    @Query("select count(*) from Car")
    long getCount();