@Entity
@Table(name = "product")
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
public class Product {
@Id
@Column(name = "id")
@GeneratedValue()
private Integer id;
@Column(name = "shortDescription")
private String shortDescription;
書
@Entity
@DiscriminatorValue(value = "Book")
public class Book extends Product {
@Column(name = "isbn")
private String isbn;
控制器
@RequestMapping(value="/product/add",
method = RequestMethod.POST)
public String addProduct(@ModelAttribute("product")
Product product, BindingResult result
){
if(null == product.getId()){
productService.addProduct(product);
}else{
productService.updateProduct(product);
}
return "redirect:/";
}
JSP,在那裏我試圖顯示這個屬性
<head>
<title>Products - Acme Web Store</title>
<script type="text/javascript">
function deleteProduct(productId){
if(confirm('Do you want to delete this product ?')){
var url = 'delete/'+productId;
window.location.href = url;
}
}
</script>
</head>
<body>
<h2>Product Store - Acme Web Store</h2>
<p style="color: green; font-weight: bold;">
To add a new product please click <a href="<c:url var="action" value="/product/add"></c:url>"> <img
src="<c:url value='/images/vcard_add.png' />"
title="Add a New Product" />
</a>
</p>
<c:url var="action" value="/product/add"></c:url>
<form:form method="post" action="${action}" commandName="product"
cssClass="productForm">
<table>
<c:if test="${!empty product.title}">
<tr>
<td><form:label path="id" cssClass="productLabel">
<spring:message code="label.productId" />
</form:label></td>
<td><form:input path="id" readonly="true" size="8"
disabled="true" /> <form:hidden path="id" /></td>
</tr>
</c:if>
<tr>
<td><form:label path="title" cssClass="productLabel">
<spring:message code="label.productTitle" />
</form:label></td>
<td><form:input path="title" /></td>
</tr>
<tr>
<td><form:label path="shortDescription" cssClass="productLabel">
<spring:message code="label.shortDescription" />
</form:label></td>
<td><form:input path="shortDescription" /></td>
</tr>
<tr>
<td><form:label path="isbn" cssClass="productLabel">
<spring:message code="label.isbn" />
</form:label></td>
<td><form:input path="isbn" /></td>
</tr>
<tr>
<td><form:label path="format" cssClass="productLabel">
<spring:message code="label.format" />
</form:label></td>
<td><form:input path="format" /></td>
</tr>
<tr>
<td colspan="2"><c:if test="${!empty product.productName}">
<input type="submit"
value="<spring:message code="label.editproduct"/>" />
</c:if> <c:if test="${empty product.productName}">
<input type="submit"
value="<spring:message code="label.addproduct"/>" />
</c:if></td>
</tr>
<tr>
<td><form:label path="type" cssClass="productLabel">
<spring:message code="label.type" />
</form:label></td>
<td>
<form:select path="type">
<form:option value="0" label="Select One" />
<form:option value="1" label="Book" />
<form:option value="2" label="Game" />
</form:select>
</td>
</tr>
</table>
</form:form>
<h3>List of products in Library</h3>
<c:if test="${!empty productList}">
<table class="productTable">
<tr>
<th width="160">Product Title</th>
<th width="190">Product Short Description</th>
<th width="80">Product ISBN</th>
<th width="80">Product Format</th>
<th width="60">Action</th>
</tr>
<c:forEach items="${productList}" var="product">
<tr>
<td><a href="<c:url value='/edit/${product.id}' />">${product.productName}</a>
</td>
<td>${product.title}</td>
<td>${product.shortDescription}</td>
<td>${product.isbn}</td>
<td>${product.format}</td>
<td><img src="<c:url value='/images/vcard_delete.png' />"
title="Delete product"
onclick="javascript:deleteproduct(${product.id})" /> <a
href="<c:url value='/edit/${product.id}' />"> <img
src="<c:url value='/images/vcard_add.png' />"
title="Edit product" />
</a></td>
</tr>
</c:forEach>
</table>
</c:if>
</body>
</html>
我得到這個錯誤: invalid property 'isbn' of bean class [com.mycompany.app.model.Product]: Bean property 'isbn' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
我知道我不是這樣做的權利,必須有鑄造產品手冊,以便我能得到ISBN財產的一種方式,我們怎麼辦呢?
讓我們看看你的''綁定和你有的getters/setters。 –
我在這裏發佈的jjsp代碼片段位於
的內部,是的,我希望看到它。我也想看看你在哪裏填充你的模型。 –