2016-03-08 123 views
0

片断我的弹簧MVC的是角JS,弹簧MVC角JS代码不是在弹簧工作

 @RequestMapping(value = "/list2", method = RequestMethod.GET,headers="Accept=*/*",produces = "application/json") 
    public ResponseEntity<List<Employe>> listAllUsers() {  
    List<Employe> users = dataService.getList(); 

    if(users.isEmpty()){ 
    return new ResponseEntity<List<Employe>>(HttpStatus.NO_CONTENT); 
} 
     return new ResponseEntity<List<Employe>>(users, HttpStatus.OK); 
    } 

我的角的js控制器就像下面

'use strict'; 

变种应用= angular.module( '应用',[]);

app.controller('EmpController', function($scope, httpq) { 

    httpq.get('http://localhost:8080/SpringHibernate/list2') 
    .then(function(data) { 
    $scope.users = data; 
    }) 
    .catch(function(data, status) { 
    console.error('Gists error', response.status, response.data); 
    }) 
    .finally(function() { 
    console.log("finally finished gists"); 
    }); 
}); 

我的index.jsp是

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
pageEncoding="ISO-8859-1"%> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd"> 
    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
<html> 
    <head ng-app="app" > 
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859- 1"> 
    <title>SpringHibernate</title> 
    </head> 
    <body > 
    <h1>Welcome to Spring Hibernate Project!!!</h1> 
    <a href="/SpringHibernate/form">Please Click this Link To Proceed</a> 
     <a href="/SpringHibernate/list3">Please Click this Link To Proceed</a> 

    <div ng-controller="EmpController"> 
    <!--Body content--> 
    <input ng-model="query"> Type to Search</input> 
    <ul> 
    <li ng-repeat="user in users | filter:query | orderBy:orderProp"> 
     <p>{{user.firstName}} 
     <p>{{user.lastName}} 
     <p>{{user.email}} 
     <p>{{user.phone}} 
    </li> 
    </ul> 

</div> 

    <script src="<c:url value="/resources/js/angular.min.js" />"  type="text/javascript"></script> 
    <script src="<c:url value="/resources/js/app.js" />" type="text/javascript"></script> 
    </body> 
    </html> 

启动代码我既不让任何登录我的浏览器,它看起来像角没有执行在所有之后。请让我知道还需要其他细节。我在Postman中使用了相同的URL,它成功地生成了JSON响应。

+0

你在控制台中是否有错误? – ochi

回答

0

您将ng-app属性放在<head>元素上。所以,只有头部被角度处理。剩下的就是纯粹的静态HTML,角度并不在意。

投入<html><body>

请注意,如果您的html代码正确缩进,错误会更容易被发现。

+0

谢谢JB我在做一些愚蠢的事情;) – Anurag