Play 2.0 Java:无法将列表传递到模板中 [英] Play 2.0 Java: Can't pass List into template

查看:64
本文介绍了Play 2.0 Java:无法将列表传递到模板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将问题列表传递到Play 2.0的模板中.

I am trying to pass a list of questions into a template in Play 2.0.

控制器代码如下:

List<Question> questions = Question.findAll();
return ok(questions.render("Here are all the questions", questions));

Template构造函数如下

The Template constructor looks like this

 @(message: String, questions: List[Question])

模板文件称为questions.scala.html

稍后,我还将在模板中使用以下问题列表:

I also use the questions list like this later in the template:

@questions_list(questions)

和`questions_list.scala.html)的构造函数如下:

and the constructor for `questions_list.scala.html) looks like this:

@(questions: List[Question])

我收到了编译错误:

cannot find symbol [symbol: method render(java.lang.String,
java.util.List<models.Question>)] 
[location: interface java.util.List<models.Question>]

我尝试清理并重新编译时没有运气吗?有人看到这里有什么问题吗?

I have tried cleaning and recompiling with no luck? Does anybody see whats wrong here?

推荐答案

好,所以问题出在我的模板和我分配给List<Question>的变量名之间的命名冲突.我想我可能会开始用大写字母命名模板,以便在控制器中使用它们时更恰当地说明它们是类.

OK so the problem was a naming collision between my template and the variable name I was assigning to the List<Question>. I think I may start naming my templates with uppercase to more properly illustrate that that they are classes when I am using them in controllers.

这篇关于Play 2.0 Java:无法将列表传递到模板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆