angular 提交post 后台使用httpServletRequest , @RequestParam 获取不到值。
需要通过 @RequeBody 注解。
为解决此问题,需要修改Post请求:
如下添加此类容 :
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
transformRequest: function(obj) {
var str = [];
for (var p in obj) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
}
post请求如下:
$http({
method: 'post',
url: '/mq/sendMq',
data: {
"xmlContent": $scope.mq_xml
},
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
transformRequest: function(obj) {
var str = [];
for (var p in obj) {
str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p]));
}
return str.join("&");
}
}).success(function(response) {
});
后台Java则可以使用获取到值:
String xmlContent = request.getParameter("xmlContent");
①:
注意: js
data: { "name": $scope.user.name, "age": $scope.user.age} 与 data: $scope.user 这种参数传递的区别;