我的数据模型:
public class Tour extends Model {
@Id
public Integer id;
@ManyToOne
public Sport sport;
@OneToOne(mappedBy="genericTour")
FootballTour footballTour;
@OneToOne(mappedBy="genericTour")
TennisTour tennisTour;
public static Finder<Integer, Tour> find(){
return new Finder<Integer,Tour>(Integer.class,Tour.class);
}
}
public class FootballTour extends Model {
@Id
public Integer id;
@OneToOne
Tour genericTour;
public static Finder<Integer, FootballTour> find(){
return new Finder<Integer,FootballTour>(Integer.class,FootballTour.class);
}
}我的行为(只是为了显示我正在获取"footballTour"):
public static Result getToursBySportTag(String sportTag){
Query query = Tour.find().fetch("sport").fetch("footballTour");
List<Tour> finedTours = query.where().eq("tag", sportTag).findList();
return ok(tours.render(finedTours));
}在scala模板中,我想访问旅游的footballTour字段:
@(tours: List[Tour])
@main("Football tours") {
<h1>Football tours List</h1>
<dl>
@for(tour <- tours) {
<dt>
<a href="@routes.Application.tour(tour.id)">
@tour.footballTour.id
</a>
</dt>
}
</dl>
}并在编译时出现错误:
错误一错误发现错误{file:/C:/Users/pc/prog/}prog/compile:compile: C省略失败信息编译一个Scala源代码到C:\Users\pc\prog\target\scala-2。9.1级.error C:\Users\pc\prog\target\scala-2.9.1\src_managed\main\views\ html\tours.template.scala:37:无法在models.Tour error“”、display(SeqAny)、format.RAW/8.11/(“”-“”)、display(SeqAny)、Forat.RAW/8.35/(“错误)中访问变量footballTour。
发布于 2012-11-08 14:31:17
genericTour类的字段FootballTour应该是公共的:
public class FootballTour extends Model {
@Id
public Integer id;
@OneToOne
public Tour genericTour; // <<<<< Here !!
public static Finder<Integer, FootballTour> find(){
return new Finder<Integer,FootballTour>(Integer.class,FootballTour.class);
}
}默认情况下,在java中,字段是私有的。
https://stackoverflow.com/questions/13290945
复制相似问题