【发布时间】:2015-01-08 17:32:42
【问题描述】:
我正在尝试在前端使用 AngularJS 并使用 Resteasy 作为 Rest API。 我的问题是使用 AngularsJS 发送参数时我的 @FormParam 始终为空。
这是我的 JS:
$scope.addPerson = function(newFirstName, newLastName) {
$http({
method: 'POST',
url: "rest/persons/savePerson",
data: {firstName: 'newFirstName', lastName: 'newLastName'},
headers: {'Content-Type': 'application/json'}
})
.success(function(data) {
alert("DATA : " + data);
}).error(function(data, status, headers, config) {
alert("Could not save new person");
});
};
这是我的代码服务器端:
@POST
@Path("/savePerson")
@Produces("application/json")
@Secured({ "ROLE_USER" })
public PersonBean savePerson(@FormParam("firstName") String firstName,
@FormParam("lastName") String lastName) {
if (firstName== null || lastName== null) {
return null;
}
PersonBean person = personDao.savePerson(firstName,
lastName);
return person ;
}
感谢任何帮助。
【问题讨论】:
标签: java javascript angularjs resteasy