[英]Is there a way to extract primary key(or ROWID) using NamedParameterJdbcTemplate and GeneratedKeyHolder?
[英]Using JSTL to extract a primary key
我試圖使用JSTL在動態生成的表的每一行上獲取一個刪除按鈕。 使用forEach方法生成表時,所有數據庫字段都沒有問題。 當我嘗試對ID(整數和表主鍵)執行相同操作時,它會在類型logon.Car上找到錯誤“Property'cars_id'”。 可以使用resultList.get(1).getID()從結果列表中提取它們,並且它在屏幕上打印到jsp頁面沒問題。
這里有什么我想念的嗎? 有任何想法嗎?
我的JSP:
<%
List<Car> resultList = new ArrayList<Car>();
resultList=(List<Car>)request.getAttribute("ResultList");
%>
<table border="1">
<thead title="Current Cars"/>
<tr><th>Make:</th><th>Model:</th><th>Year:</th><th>Colour:</th><th>Information:</th></tr>
<tbody>
<c:forEach items="${ResultList}" var="car">
<tr>
<td>${car.carMake}</td>
<td>${car.model}</td>
<td>${car.carYear}</td>
<td>${car.carColour}</td>
<td>${car.information}</td>
<td>
<form action="CarServlet" method="get">
<input type="hidden" name="carId" value="${car.cars_id}" />
<input type="submit" value="Remove" name="remove">
</form>
</td>
</tr>
</c:forEach>
</tbody>
</table>
我的Car.java
@Entity
@Table(name = "cars")
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int cars_id;
@Column(name = "cars_make")
private String carMake;
@Column(name = "year")
private String carYear;
@Column(name = "colour")
private String carColour;
@Column(name="information")
private String information;
@Column(name="model")
private String carModel;
//NOTE:"user_id" below in (@JoinColumn(name="user_id"))...is the name
//of the field in my sql that corresponds to id from User table
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({ @JoinColumn(name = "user_id", referencedColumnName="id") })
private User user;
public User getUser() {
if (user == null) {
user = new User();
}
return user;
}
public void setUser(User user) {
this.user = user;
}
public int getCar_id() {
return cars_id;
}
public void setCar_id(int cars_id) {
this.cars_id = cars_id;
}
public String getCarMake() {
return carMake;
}
public void setCarMake(String carMake) {
this.carMake = carMake;
}
public String getModel() {
return carModel;
}
public void setModel(String carModel) {
this.carModel = carModel;
}
public String getCarYear() {
return carYear;
}
public void setCarYear(String carYear) {
this.carYear = carYear;
}
public String getCarColour() {
return carColour;
}
public void setCarColour(String carColour) {
this.carColour = carColour;
}
public String getInformation() {
return information;
}
public void setInformation(String information) {
this.information = information;
}
}
${car.cars_id}
應為${car.car_id}
EL
字段名稱應與bean方法名稱匹配,而不是與類字段本身匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.