0

我是Playframework和AngularJS的新手,并在前端的AngularJS和后端的Playframework上开发应用程序。Playframework将json值转换为表格

我面临一种情况:当用户点击菜单链接(显示学生)时,它应该显示所有的学生。在播放操作中,数据以json的形式发送。现在的问题是,如果数据是作为Json发送的,那么我看不到它应该转发到哪个页面的选项。 或者,我必须使用正常的playframework风格,例如转发到带有值列表的页面。

//This is the current playframework code I use. Here I set the values to students form 
// This is not the way I want 
public static Result getAllEmployees(){ 
     List<Student> all = Student.find.all();  
     JsonNode json = Json.toJson(all); 
     return ok(views.html.students.render(all)); 
} 


//This is the way I want 
public static Result getAllEmployees(){ 
     List<Student> all = Student.find.all();  
     JsonNode json = Json.toJson(all); 
     return ok(json); // no option for specifying the page. 
} 

有没有办法做到这一点?

回答

0

它们都是返回数据的有效方法,但第一个返回整个html页面,例如响应您视图中的@routes.Employees.getAllEmployees引用。第二个仅返回Json内容类型响应,例如响应Javascript请求或AngularJS $http.get。这些方法需要具有不同的名称(它们不能被称为getAllEmployees)。他们都将在路线文件中有条目。他们将不同的条目你写他们的方式,因此,或许是这样的:

GET /employee controllers.Employees.getAllEmployees 
GET /api/employee controllers.Employees.apiGetAllEmployees 

(声明:我没有在AngularJS这样做还,但原则应该是相似的)