大佬教程收集整理的这篇文章主要介绍了AngularJs在我的spring控制器中形成发布数据以提供空值,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
没有指定用于将JsON转换为Java对象的映射器。
如果要将JsON转换为UserRegistration的对象,请使用Jackson(dore,databind,Annotations)。
需要在下面的dispatcher-servlet中添加。这是用于将JsON映射到Java对象:
<beans:bean
class="org.springframework.web.servlet.mvc.method.Annotation.requestMapPingHandlerAdapter">
<beans:property name="messageConverters">
<beans:List>
<beans:ref bean="JsonmessageConverter" />
</beans:List>
</beans:property>
</beans:bean>
<!-- Configure bean to convert JsON to POJO and vice versa -->
<beans:bean ID="JsonmessageConverter"
class="org.springframework.http.converter.Json.MapPingJackson2httpmessageConverter">
</beans:bean>
控制器中的方法是这样的吗?
@requestMapPing(value = "/save", method = requestMethod.POST, headers = "Accept=application/Json")
public String saveUser(@requestbody UserRegistration userReg) {
System.out.println(userReg.getFirstname()+" "+userReg.getLastname());
userDao.registerUser(userReg);
return "success";
}
如果您没有回复网页以消耗结果,请在上方使用。如果您希望从此方法返回某些内容并在网页中显示或在其他地方使用,则方法的声明将更改为:
public @ResponseBody String saveUser(@requestbody UserRegistration userReg)
$scope.post = function() {
$scope.data = null;
$http({
method : 'POST',
url : 'save',
params : {
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
}
}).success(function(data, status, headers, config) {
$scope.List.push(data);
}).error(function(data, status, headers, config) {
alert("Exception");
});
};
你好,我正在尝试使用angular发布表单,但是我在spring
controller中获取了空值。在控制台中,我也看到了sysout的空值。此外,即使我看到控制台上印有公牛,我也会收到错误警报。
我的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,config) {
alert( "Exception details: " + JSON.Stringify({data: data}));
});
}
};
我的Spring控制器
@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";
}
以上是大佬教程为你收集整理的AngularJs在我的spring控制器中形成发布数据以提供空值全部内容,希望文章能够帮你解决AngularJs在我的spring控制器中形成发布数据以提供空值所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。