我正在学习游戏框架,我希望列出一些订单,然后在单击订单后将提供其中的产品详细信息。我有正常工作的订单列表(索引类中的标题模型),但是单击该订单时,它会为每个不正确的订单提供相同的产品详细信息(使用产品模型显示类)。任何建议都将非常感谢
public Result index(){
List<Heading> headings = Ebean.find(Heading.class)
.where()
.eq("CustomerID", "74")
.orderBy("DateOrder desc")
.setFirstRow(0)
.setMaxRows(10)
.findList();
return ok(index.render(headings)) ;
}
public Result show(Integer id){
List<Product> products = Ebean.find(Product.class)
.setFirstRow(0)
.setMaxRows(10)
.findList();
return ok(show.render(products)) ;
}
@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")
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;
@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;
public static Finder<Integer, Product> find = new Finder<>(Product.class);
}
@(headings : List[Heading])
@Layout("All Books") {
<h1> All Books</h1>
@for(heading <- headings) {
<a class="btn btn-link" href="@routes.BooksController.show(heading.JobKeyID)">@heading.Name</a>
<p> JobNumber : @heading.JobNumber</p>
<p> Price : @heading.SellingPriceIncTax</p>
<p> Author : @heading.DateOrder</p>
}
}
@(products : List[Product])
@Layout("All Books") {
<h1> All Books</h1>
@for(product <- products) {
<p> Design Name : @product.DesignName</p>
}
}
GET /headings controllers.BooksController.index
GET /headings/:id controllers.BooksController.show(id: Integer)