前端代码
var app = angular.module('myApp', ['ngResource']);
app.controller('UserController', ['$scope', '$resource',function($scope,$resource)
{
$scope.deleteRec = function(username)
{
User = $resource(
'delete/:username',
{},
{method:'DELETE', params: {username: '@username'}});
User.delete({username: $scope.myform.username}).$promise.then(function successCallback(response)
{
$scope.Message = response;
}, function errorCallback(response) {
});
$scope.myform.username = "";
$scope.myform.phone="";
$scope.myform.email="";
};
}]);
<table border="1" width="50%" height="50%">
<tr><th>user_name</th><th>phone</th><th>email</th><th>delete</th></tr>
<tr data-ng-repeat="user in usernames">
<td><span data-ng-bind="user.username"></span></td>
<td><span data-ng-bind="user.phone"></span></td>
<td><span data-ng-bind="user.email"></span></td>
<td><button data-ng-click="deleteRec(user.username)">delete</button>
</tr>
</table>
弹簧控制器代码
@RequestMapping(value="/delete/{username}")
@ResponseBody
public String delete(@PathVariable String username)
{
String user=retrievedataservice.delete(username);
return user;
}
如何通过 angularjs 请求删除特定记录。Angularjs不将参数发送到spring控制器