在我的数据库中,我有 3 个表,显示在图像上。我不想从存储表中获取数据并以形式显示。但我的清单有问题。数据库中的查询工作良好,程序中也有对象,但不想显示在表单上。什么问题??
实体店
@Entity
@Table(name = "store")
public class Store{
private int id;
private String name;
private String address;
public Store(){
name = null;
}
public Store(Store store){
name = store.getName();
}
@Id
@GeneratedValue(generator = "increment")
@GenericGenerator(name = "increment", strategy = "increment")
@Column(name = "id")
public int getId(){
return id;
}
@Column(name = "name")
public String getName(){
return name;
}
@Column(name = "address")
public String getAddress(){
return address;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setAddress(String address) {
this.address = address;
}
//refer Store[idDirector] -> User[id]
//@Column(name = "idDirector")
private User user;
@ManyToOne//(fetch = FetchType.LAZY)
@JoinColumn(name = "idDirector")
public User getUser(){
return user;
}
public void setUser(User user){
this.user = user;
}
//refer Store[idType] -> StoreType[id]
private StoreType storeType;
@ManyToOne//(fetch = FetchType.LAZY)
@JoinColumn(name = "idType")
public StoreType getStoreType(){
return storeType;
}
public void setStoreType(StoreType storeType){
this.storeType = storeType;
}
//\refer
//refer Store[id] -> CatalogStore[idStore]
private Set<CatalogStore> catalogStores = new HashSet<CatalogStore>(
0);
@OneToMany//(fetch = FetchType.LAZY)
public Set<CatalogStore> getCatalogStore(){
return this.catalogStores;
}
public void setCatalogStore(Set<CatalogStore> catalogStores){
this.catalogStores = catalogStores;
}
//\refer
}
DAO 获取列表方法
@Override
public List<Store> getAllStoresWithoutCurrentGoods(int userId, int goodsId) throws SQLException {
Session session = null;
Transaction tx = null;
List<Store> stores = new ArrayList<Store>();
try {
session = this.sessionFactory.openSession();
tx = session.beginTransaction();
stores = session.createSQLQuery("select t1.id, t1.name, t1.idType, t1.idDirector " +
"from Store t1 " +
"join store_catalog t2 on(t1.id = t2.idStore) " +
"where t1.idDirector = " + userId + " and t2.idGoodsOnFirm <> " + goodsId + " group by t1.id").list();
//alternative in hql
/*stores=session.createQuery("from Store u, CatalogStore u1 " +
"where (u.user.id = :userId) and " +
"(u1.catalogCompany.id != :goodsId)" +
"group by u.id")
.setParameter("goodsId", goodsId).setParameter("userId", userId).list();*/
tx.commit();
} catch (Exception e) {
if (tx != null)
tx.rollback();
e.printStackTrace();
} finally {
if (session != null && session.isOpen())
session.close();
}
return stores;
}
看法
<c:if test="${!empty storeList}">
<table>
<c:forEach items="${storeList}" var="store">
<tr class="editField">
<td><c:out value="${store.id}" />
</td>
<td><c:out value="${store.name}" />
</td><!--
<td><//c:out value="${store.storeType.name}" />
</td>
<td><//c:out value="${store.address}" />
</td>-->
<td><input type="button" id = 'addInThisStore' value="Add"></td>
</tr>
</c:forEach>
</table>
堆栈跟踪
58: <c:forEach items="${storeList}" var="store">
59: <tr class="editField">
60:
61: <td><c:out value="${store.id}" />
62: </td>
63: <td><c:out value="${store.name}" />
64: </td><!--
Stacktrace:] with root cause
java.lang.NumberFormatException: For input string: "id"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at javax.el.ArrayELResolver.coerce(ArrayELResolver.java:158)
...