AngularJS ng-click与调用控制器功能不起作用

时间:2018-11-02 04:32:48

标签: java angularjs spring-mvc

<button id="submit_btn" class="btn btn-primary" data-ng-click='getData();'>Get User</button>
 <table border="1" width="50%" height="10%"> 
    <tr><th>username</th><th>phone</th><th>email</th><th>Delete</th><th>edit</th></tr>
    <tr data-ng-repeat="u in users">
    <td><span data-ng-bind="u.userBean.username"></span></td>
    <td><span data-ng-bind="u.userBean.phone"></span></td>
     <td><span data-ng-bind="u.userBean.email"></span></td>
     </tr>

Angular js

<script type="text/javascript">
var app = angular.module('myApp', []);
app.controller("UserController", ['$scope', '$http', function($scope, $http, httpPostService) {
 var self=this;
 $scope.getData = function()
 {
     $http({
         method: "GET",
         url: 'retrieve',
     }).then(function(response) {
         $scope.users = response.data;
         console.log("Success");
     }, function(response) {
         $scope.err_state = true;
         console.log("Failure");
     });
 };
}]);
</script>

控制器类

@RequestMapping(value="/retrieve", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public List<UserBean> retrieves(HttpServletRequest request, HttpServletResponse response, @ModelAttribute @Valid UserBean userBean,BindingResult result)
    {
        List<UserBean> users=retrieveService.findAllUsers(userBean);
        return users;   
    }

实际上,我从mysql检索数据到前端,但是getData()函数没有执行。像这样

SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/SpringAngular] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause
java.lang.NullPointerException

在angular js控制台中显示如下 加载资源失败:服务器响应状态为500()

0 个答案:

没有答案