我对repo有一个简单的定义:
public interface StorageService extends CrudRepository<Car, Long> {}
我可以使用curl来创建和查看元素。get和create (分别)示例如下:
curl -v http://localhost:8080/cars
curl -i -X POST -H "Content-Type:application/json" -d '{"licensePlate" : "Vegan is Moral" }' http://localhost:8080/cars
基本上,我使用的是CrudRepository的save()
和findAll()
方法。
如何使用curl调用count()
方法,这也是在CrudRepository
中定义的(不定义其他服务)?
发布于 2018-02-21 22:06:21
我认为这是不可能的。
在我看来(可能是我错了),这是因为spring数据rest基本上是通过HTTP方法(GET、POST……)提供rest端点。用于对资源(实体)执行操作,get count不是HTTP操作
但您可以通过其他几种方法来实现这一点。
Car countByModel(String model);
这将使GET端点在/car/search/countByModel处可用
或者像这样
这将使GET端点在/cars/search/getCount上可用
https://stackoverflow.com/questions/48914018
复制相似问题