你好,我想发布一个窗体使用角度,但我得到null值在我的弹簧controller.Also在我的控制台我看到空值为sysout.Moreover我即使我看到公牛印在我的控制台上,也会收到错误警报。AngularJs形式发布数据在我的弹簧控制器中给出null值
我的JS控制器
angular.module('ngMailChimp', ['ngAria', 'ngMessages', 'ngAnimate'])
.controller('SignUpController', function ($scope, $http) {
$http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded; charset=utf-8";
var ctrl = this,
newCustomer = { firstName:'',lastName:'',email:'',streetName:'',aptName:'',cityName:'',stateName:'',countryName:'', zipName:'', userName:'',password:'' };
var signup = function() {
if(ctrl.signupForm.$valid) {
ctrl.showSubmittedPrompt = true;
var formData = {
'firstName' : $scope.ctrl.newCustomer.firstName,
'lastName' : $scope.ctrl.newCustomer.lastName,
'email' : $scope.ctrl.newCustomer.email,
'streetName' : $scope.ctrl.newCustomer.streetName,
'aptName' : $scope.ctrl.newCustomer.aptName,
'cityName' : $scope.ctrl.newCustomer.cityName,
'stateName' : $scope.ctrl.newCustomer.stateName,
'countryName' : $scope.ctrl.newCustomer.countryName,
'zipName' : $scope.ctrl.newCustomer.zipName,
'userName' : $scope.ctrl.newCustomer.userName,
'password' : $scope.ctrl.newCustomer.password
};
var response = $http.post('http://localhost:8080/Weber/user/save', JSON.stringify(formData));
response.success(function(data, status, headers, config) {
$scope.list.push(data);
});
response.error(function(data, status, headers, config) {
alert("Exception details: " + JSON.stringify({data: data}));
});
}
};
我的春天控制器
@RestController
@RequestMapping(value = "/user")
public class UserRegistrationControllerImpl implements UserRegistrationController {
@Autowired
UserRegistrationDao userDao;
@RequestMapping(value = "/save", method = RequestMethod.POST)
public String saveUser(UserRegistration userReg) {
System.out.println(userReg.getFirstName()+" "+userReg.getLastName());
userDao.registerUser(userReg);
return "success";
}
请帮我
谢谢 标志。
但我得到的回复在所有字段为空 – mark
@mark请检查编辑并让我知道。 – HARDI
当我把类似于你的建议作为第一次编辑提示我抛出“客户端发送的请求在语法上不正确”。对于第二个也是当我尝试称它形成我的角度我的意思是当我尝试发布使用我的angularjs的东西同样的错误显示 – mark