以下是LocationSearchMetaData.java
public class LocationSearchMetaData {
private int page;
private String tag;
private SearchPreferences prefs;
private PublishMsgSearchLocality locality;
public PublishMsgSearchLocality getLocality() {
return locality;
}
public void setLocality(PublishMsgSearchLocality locality) {
this.locality = locality;
}
public SearchPreferences getPrefs() {
return prefs;
}
public void setPrefs(SearchPreferences prefs) {
this.prefs = prefs;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
public String getTag() {
return tag;
}
public void setTag(String tag) {
this.tag = tag;
}
}
SearchPreferences.java
public abstract class SearchPreferences {
private String radius;
private boolean useCurrLoc;
public boolean isUseCurrLoc() {
return useCurrLoc;
}
public void setUseCurrLoc(boolean useCurrLoc) {
this.useCurrLoc = useCurrLoc;
}
public String getRadius() {
return radius;
}
public void setRadius(String radius) {
this.radius = radius;
}
}
PublishMsgSearchLocality.java
public class PublishMsgSearchLocality {
private String formatted_address;
private double lat;
private double lon;
public String getFormatted_address() {
return formatted_address;
}
public void setFormatted_address(String formatted_address) {
this.formatted_address = formatted_address;
}
public double getLat() {
return lat;
}
public void setLat(double lat) {
this.lat = lat;
}
public double getLon() {
return lon;
}
public void setLon(double lon) {
this.lon = lon;
}
}
我的控制器
@RestController
@CrossOrigin
@RequestMapping("/api/v1.0/search")
public class SearchController {
@Autowired
private SearchService search;
@Autowired
private AppInstances instances;
@RequestMapping(value="tag",method=RequestMethod.POST)
public List<PublishMessageSearchModel> searchByTag(@RequestBody LocationSearchMetaData metaData)
{
return search.search(instances.getEsClient(), metaData.getLocality().getLat(), metaData.getLocality().getLon(), Integer.parseInt(metaData.getPrefs().getRadius()), metaData.getTag(), metaData.getPage());
}
}
我的客户请求就像这样
var req = {
method: 'POST',
url: 'http://192.168.1.2:8084/mobapp/api/v1.0/search/tag',
headers: {
'Content-Type': "application/json"
},
data: searchFormService.getTagSearhReqData()
};
$http(req).then(function(d){
console.log("search data :: "+JSON.stringify(d));
}, function(e){
以下是实际数据请求的方式
{"prefs":{"radius":"25","useCurrLoc":true},"page":1,"locality":{"formatted_address":"mylocation","lat":11.9313,"lon":60.579999999},"tag":"tag3"}
我收到错误:
HTTP Status 400 : The request sent by the client was syntactically incorrect.
答案 0 :(得分:0)
尝试逃避引号:\"
。
{\"prefs\":{\"radius\":\"25\",\"useCurrLoc\":true},\"page\":1,\"locality\":{\"formatted_address\":\"mylocation\",\"lat\":11.9313,\"lon\":60.579999999},\"tag\":\"tag3\"}
<强>更新强>
您将类SearchPreferences
定义为抽象。您需要删除此修饰符并可能添加空构造函数(可能需要JSON映射器)。