我在数据库中有两个表
类别表,其中包含(categoryId
,categoryName
)
产品表,其中包含(productId
,productName
,price
,categoryId
)
我已经在jsp页面中检索了产品表,但是我希望将categoryId
替换为category name
<c:forEach items="${products}" var="product">
<tr>
<td>${p.productName}</td>
<td>${p.price}</td>
<td>${p.categoryId}</td> // want to replace categoryId with category name here
</tr>
<c:forEach>
答案 0 :(得分:1)
您的@OneToMany
和Category
实体之间应该存在双向Product
关系。
加载所有Product's
后,如果您将抓取策略设置为Category
,JOIN
也将加载。现在,如果您将产品传递给jsp,那么您可以访问类别名称:
${p.category.categoryName}