你好,我想發佈一個窗體使用角度,但我得到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