MongoDB、SpringData、FindByposition靠近更多参数
Hi有以下实施:MongoDB、SpringData、FindByposition靠近更多参数,mongodb,spring-data,Mongodb,Spring Data,Hi有以下实施: public class Store { private double[] position; private String category; } 这种方法用于搜索附近的商店 public List<Store> fundByLatLong(double latitude, double longitude, Double km) { mongoTemplate.indexOps(Store.class).ensureIndex(new Geosp
public class Store {
private double[] position;
private String category;
}
这种方法用于搜索附近的商店
public List<Store> fundByLatLong(double latitude, double longitude, Double km) {
mongoTemplate.indexOps(Store.class).ensureIndex(new GeospatialIndex("position"));
Point point= new Point(latitude, longitude);
List<Store> stores= this.storeRepository.findByPositionNear(ponto , new Distance(km, Metrics.KILOMETERS));
return stores;
}
public List fundByLatLong(双纬度、双经度、双公里){
mongoTemplate.indexOps(Store.class).ensureIndex(新的地理空间索引(“位置”));
点=新点(纬度、经度);
List stores=this.storeRepository.findByPositionNear(ponto,新距离(km,Metrics.km));
退货商店;
}
但我需要按职位和类别搜索。如何为“查找”添加参数类别?这就是您要查找的吗
interface StoreRepository extends Repository<Store, Long> {
List<Store> findByCategoryAndPositionNear(String category,
Point point, Distance distance);
}
接口存储库扩展存储库{
列出findByCategoryAndPositionNear(字符串类别,
点、点、距离);
}
有关这类内容的详细信息,请参见。是的,但此接口不是SpringData中的本机接口SpringData本机接口是findByPositionNear(点p,距离d)。SpringData在运行时实现此接口。我如何告诉SpringData实现我需要的接口?你说的“非本机”是什么意思?上面显示的接口定义只是开箱即用。您不能告诉Spring数据实现任意接口。您的界面需要遵守Spring数据支持的功能,或者自己实现repo的各个部分。所有这些都记录在文档中。