【发布时间】:2017-11-27 12:04:26
【问题描述】:
我正在尝试将一个字符串从我的视图发送到我的控制器,但我不断收到“文本”不存在的错误。
这是我的javascript
$scope.sendMsg = function(){
console.log($scope.my.message);
data = {"text" : $scope.my.message};
$http({
method:'POST',
data:data,
contentType: "application/json; charset=utf-8",
dataType:"json",
url:'/post-stuff'
}).then(function(response){
console.log(response);
});
}
我的休息控制器:
@RequestMapping(value= "/post-stuff", method=RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<PostTextResult> postStuff(@RequestParam(value= "text") String text){
System.out.println(text);
return new ResponseEntity<PostTextResult>(stuff.postTextContent(text), HttpStatus.OK);
}
【问题讨论】:
-
在发送前尝试对数据进行字符串化
-
从查询参数中提取了一个
@RequestParam值。你没有。data是正文,为 json。
标签: javascript java angularjs spring-mvc spring-boot