Play Framework begginner。试图实现模型

时间:2017-01-26 14:19:53

标签: java scala playframework

我正在学习Play框架,我解决了一些练习题。我想编译代码,但我有一个错误,我无法弄清楚错误是什么。

我期待这样的输出: output

HomeController.java

public class HomeController extends Controller {

public Result index() {
    int level = 1;

    Item item = new Item();
    item.User = "user1";
    item.timestamp = LocalTime.now();
    item.message = "the first message testing";

    Item item2 = new Item();
    item2.User = "user2";
    item2.timestamp = LocalTime.now();
    item2.message = "the second message testing";


    java.util.List<String> list= {item, item2};
    return ok(index.render("it works!", level, asScalaBuffer(list)));
}
}

index.scala.html

@(message: String)(level:Int, list:Seq[Item])

@main("Welcome to Play") {
<h1>@message</h1>

@listContainer{
<h@level>Level @level</h@level>
}(level, list){
<div>End of level @level</div>
}
}

listContainer.scala.html

@(header: Html)(level:Int, items:Seq[Item])(footer: Html)
@import Item

<div style="margin-left: @{5*level}%">
@header
<ul id="list@level">

@items.map { item =>
<li>@listItem(item)</li>
}
</ul>
@footer
</div>

Item.java模型

package models;

import org.joda.time.LocalTime;

public class Item{
public String User;
public LocalTime timestamp;
public String message;

public Item(String User, LocalTime timestamp, String message){
    this.User = User;
    this.timestamp = timestamp;
    this.message = message;
}
}

listItem.scala.html

@(item:Item)

<style>

li.item span{
    width: 100px;
    display: inline-block;
}
</style>

<li class="item"> <span>@item.User</span> <span>[@item.timestamp]</span> > @item.message </li>

当我运行应用程序时,我收到此错误:

/Users/andrei/play-java/app/views/listContainer.scala.html:7: '.' expected but ';' found.
<ul id="list@level"> 

我无法理解为什么。

1 个答案:

答案 0 :(得分:0)

问题在于,当您导入课程Item时,您做错了。

@import Item

但它应该是

@import models.Item