Java eclipse在play2中的render()上显示错误
我是Play框架的新手,我正在尝试开发示例java应用程序 我已经创建了新的html页面test.html 在控制器中,如果我们简单地以字符串的形式返回结果,即返回ok(“hello world”),那么它是有效的,但它只是格式化所有样式/文本,并在UI上显示“hello world”Java eclipse在play2中的render()上显示错误,java,eclipse,playframework-2.0,Java,Eclipse,Playframework 2.0,我是Play框架的新手,我正在尝试开发示例java应用程序 我已经创建了新的html页面test.html 在控制器中,如果我们简单地以字符串的形式返回结果,即返回ok(“hello world”),那么它是有效的,但它只是格式化所有样式/文本,并在UI上显示“hello world” public static Result test() { return ok("hello world"); } //工作正常 但是当我尝试这个时,它会出错 public s
public static Result test() {
return ok("hello world");
}
//工作正常
但是当我尝试这个时,它会出错
public static Result test(){
return ok(test.render());
}
//给出错误
它给出了以下错误
[错误]/opt/ahsen/play-2.2.3/testapp/app/controllers/Application.java:15:view.Html.test中的render(java.lang.String、play.api.templates.Html)无法应用于()
[错误]返回ok(test.render())
[error](compile:compile)javac返回了非零退出代码
这是我的test.html文件
@(title: String)(content: Html)
<!DOCTYPE html>
<html>
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.at("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.at("images/favicon.png")">
<script src="@routes.Assets.at("javascripts/jquery-1.9.0.min.js")" type="text/javascript">
</script>
</head>
<body>
@content
</body>
</html>
@(标题:字符串)(内容:Html)
@头衔
@内容
请提供帮助您的test.html模板需要两个参数
@(title: String)(content: Html)
因此,您需要将它们传递到控制器中的模板
public static Result test(){
String title = "test title";
Html content = // create content
return ok(test.render(title, content));
}
更好的解决方案
html看起来更像是一个通用的布局模板。我将创建一个单独的文件来生成内容,而不是直接从控制器传递它
content.html
@(title: String)
@test(title){
<span>this is the content</span>
}
public static Result test(){
String title = "test title";
return ok(content.render(title));
}