我使用彈性搜索來存儲數據(彈簧數據elasticsearch)和我,需要在我的文檔中存儲地理位置。類結構採用以下格式。彈簧數據彈性搜索GeoPoint與彈簧mvc
@Document(indexName = "outlet")
public class OutletIndex implements IESMapper {
@Id
private String path;
private String name;
@GeoPointField
private GeoPoint geoPoint;
// setters and getters
}
由於是GeoPoint
類沒有制定者不與春MVC控制器@ModelAttribute
註釋工作。我需要從正面獲得它,所以我想它更新爲:
@Document(indexName = "outlet")
public class OutletIndex implements IESMapper {
@Id
private String path;
private String name;
@GeoPointField
private GeoPoint geoPoint;
private String geoLocation;
public void setGeoLocation(String geoLocation) {
this.geoLocation = geoLocation;
if (geoLocation != null && geoLocation.trim() != "") {
String[] loc = geoLocation.split(",");
this.geoPoint = new GeoPoint(Double.parseDouble(loc[0]), Double.parseDouble(loc[1]));
}
}
// setters and getters
}
持有它的字符串表示,並且還更新GeoPiont
的二傳手內的附加字段。
有沒有更好的方法來做到這一點?
編輯:還有一個疑問,有沒有什麼辦法使用字符串作爲geopoint(逗號分隔值)?