2016-01-23 63 views
1

我必須在@OneToMany realtion中的實體。 我試圖從我的實體獲取unitPrice時出現錯誤。有誰能幫我解決這個問題嗎?Spring MVC NumberFormatException

我的實體:

@Entity 
    @Table(name="Product") 
    public class Product { 
     @Id 
     @GeneratedValue 
     private int idProduct; 
     private String status; 
     private String name; 
    @OneToMany(mappedBy = "product") 
     private List <Repository> repository; 

    @Entity 
    @Table(name="Repository") 
    public class Repository { 

     @Id 
     private int idRepository; 
     private int quantity; 
     private double unitPrice; 

     @ManyToOne 
     private Product product; 

觀點:

<c:forEach items="${products.repository}" var="product"> 
          <p>${product.unitPrice}</p> 
          </c:forEach> 

錯誤:

java.lang.NumberFormatException: For input string: "repository" 
+0

你是否試圖顯示產品列表?可以將控制器代碼發佈到設置產品對象的位置 –

回答

0

你必須使用下面的代碼在repository顯示unitPrice。 在下面的代碼中,products代表的Product對象,其中每個Product對象具有ListRepository對象。

<c:forEach items="${products}" var="product"> 
    <c:forEach items="${product.repository}" var="repo"> 
     <p>${repo.unitPrice}</p> 
    </c:forEach> 
</c:forEach>