ebean 查询 2 个模型并渲染到 html

ebean query 2 models and render to html

我在 ebean 中设置了 2 个模型,单独查询时都可以正常工作。现在我需要从我的产品和标题模型进入我的 Show.scala.html 字段,产品字段工作正常但我还需要来自标题的 DateOrder,但我得到一个编译错误值 DateOrder is not a member of objectmodels.Heading,求助

我的模型

package models;

import io.ebean.Finder;
import io.ebean.Model;
import play.data.validation.Constraints;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
@Table(name="Heading")
public class Heading extends Model {


    @Id

    @Column(name="JobKeyID")
    public Integer JobKeyID;
    @Constraints.MaxLength(50)
    @Constraints.Required
    @Column(name="Name")
    public String Name;
    @Column (name="JobNumber", columnDefinition = "NVARCHAR")
    public String JobNumber;
    @Constraints.Required
    @Column(name="SellingPriceIncTax")
    public Integer SellingPriceIncTax;
    @Constraints.Required
    @Column(name="DateOrder")
    public Date DateOrder;
    @Column(name="CustomerID")
    public Integer CustomerID;


    @OneToMany(mappedBy = "heading", fetch = FetchType.EAGER)
    public List<Product> product;

    public static Finder<Integer, Heading> find = new Finder<>(Heading.class);


}

package models;

import io.ebean.Finder;
import io.ebean.Model;
import io.ebeaninternal.server.type.ScalarTypeJsonList;
import play.data.validation.Constraints;

import javax.persistence.*;
import java.util.Date;
import java.util.List;

@Entity
@Table(name="Product")
public class Product extends Model {


    @Id

    @Column(name = "ItemKeyID")
    public Integer ItemKeyID;
    @Constraints.MaxLength(50)
    @Constraints.Required
    @Column(name = "ProductName")
    public String ProductName;
    @Column(name = "ItemNumber")
    public Integer ItemNumber;
    @Constraints.Required
    @Column(name = "DesignName")
    public String DesignName;
    @Column(name = "JobKeyID")
    public  Integer JobKeyID;
    @ManyToOne
    @JoinColumn(name="JobKeyID")
    public Heading heading;

    @OneToMany(mappedBy = "product")
    public List<Information> information;

    public static Finder<Integer, Product> find = new Finder<>(Product.class);

}

我的控制器

   public Result show(Integer id){
                    List<Product> products = Ebean.find(Product.class)
                            .fetch("heading")
                            .where().eq("JobKeyID",id)
                    .setFirstRow(0)
                    .setMaxRows(10)
                    .findList();
            return ok(show.render(products)) ;
    }

和我的scala.html

@(products : List[Product])


@Layout("All Books") {
    <h1> All Books</h1>
    @for(product <- products) {
            <a class="btn btn-link" href="@routes.BooksController.specinfo(product.JobKeyID, product.ItemKeyID)">@product.ProductName</a>
            <p> Design Name : @product.DesignName</p>
        <p> Order Date : @Heading.DateOrder</p>


            <img src ="@routes.ImagesController.getImage("419326-1.svg")"/>


        }

}

您正在尝试通过 class 获取字段 DateOrder,但它不是静态成员。我相信这是原因。如果我正确理解了您的意图,您应该将 @Heading.DateOrder 替换为 @product.heading.DateOrder