【发布时间】:2015-07-22 17:59:47
【问题描述】:
我想使用 AngularJS 和 spring mvc 将数据插入数据库,根据教程我做了所有事情,但我未能将数据插入数据库。
控制器:
@RequestMapping(value = "/add", method = RequestMethod.POST)
public @ResponseBody String addEmployee(@ModelAttribute(value="employee")EmployeeEntity employee, BindingResult result)
{
employeeManager.addEmployee(employee);
return "redirect:/";
}
js代码:
$scope.insertData = function(){
$http.post("http://localhost:9090/CrudOperations/add", {"firstname":$scope.firstname})
.success(function(data,status,header,config)
{
console.log("inserted");
});
}
jsp:
<form:form class="form-horizontal" role="form" method="post" commandName="employee">
<div class="form-group col-lg-7" >
<label for="email" class="control-label">First Name:</label>
<input type="text" ng-model="firstname" class="form-control" placeholder="Enter Firstname"/>
</div>
<div class="form-group col-lg-7">
<button type="submit" ng-click="insertData()" class="btn btn-primary">Submit</button>
</div>
【问题讨论】:
-
使用浏览器开发工具网络选项卡检查实际请求。在验证控制台中没有抛出异常后调试 ajax 时首先开始。需要状态,检查发送/返回的内容等。如果问题是客户端或服务器端,需要缩小范围
标签: angularjs spring-mvc