【发布时间】:2017-05-03 03:59:52
【问题描述】:
我正在尝试使用参数发出 angularjs $http.get 请求,但由于语法可能导致它无法正常工作。请你 确认我做错了什么,可能是angularjs调用或java api方法中的语法错误
$http.get(document.requestPathPrefix + "/home/my-api",
$scope.requestParametersObject
).then(
function(response) {
$scope.output = response.data;
},
function(response) {
$scope.retrieveErrorMssg = "Failed to retrieve required data.";
});
我的参数和这张图片一样
在 java api 中像这样调用
@RequestMapping(value = "/my-api", method = RequestMethod.GET)
public ResponseEntity<Collection<MyObjectResponse>> getMyObjResponse(@RequestBody final MyObjectRequest request)
{
Map<Integer,MyObjectResponse> oResponse = new HashMap<>();
try {
//Manipulation and db calls
} catch (Exception e) {
log.error(e.getMessage(), e);
}
return new ResponseEntity<Collection<MyObjectResponse>>(oResponse.values(), HttpStatus.OK);
}
【问题讨论】:
-
为什么你提出了一个 get 请求而不是创建一个 post 请求?
-
据我了解,在这种情况下我可以同时使用 get 或 post
标签: javascript java angularjs rest