我是AngularJS + Spring的新手。我试图通过他的ID删除当前用户。我有以下代码
user.controller.js
(function() {
'use strict';
angular.module('app').controller('UserController', function($state, $location, $stateParams, User, user) {
var vm = this;
vm.user = null;
vm.success = null;
vm.userURL = $location.path();
vm.deleteUser = function() {
vm.user.$delete({id : vm.user.id}, function(response) {
if (user.id == response.id) {
angular.extend(user, response);
}
vm.success = true;
}, function() {
vm.success = false;
});
};
})();
user.html
<md-button aria-label="DeleteUser" ng-click="uc.deleteUser()"> <md-icon md-menu-origin>clear</md-icon>Delete
User</md-button>
和UserController.java
@RestController
@ExposesResourceFor(User.class)
@RequestMapping(value = "/user", produces = MediaType.APPLICATION_JSON_VALUE)
public class UserController {
@Inject
private UserRepository userRepository;
@Inject
private UserService userService;
@Inject
private UserResourceAssembler userResourceAssembler;
@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
public void delete(@PathVariable final Long id) {
userRepository.delete(id);
}
}
如果按下删除按钮,我会得到 删除http://localhost:3000/api/user/100 403(禁止) 我必须提到put,get,post正在工作,当我访问http://localhost:3000/api/user/100时,我得到了正确的回复。
有人有建议吗? 谢谢