Hibernate 如何在表单中显示列表中的值(数据库中的值)?
在我的数据库中,我有3个表,显示在图像上。我不想从存储表中获取数据并以表单形式显示。但我的名单有问题。查询在数据库中工作良好,并且在程序中也得到了对象,但不想在窗体上显示。什么问题 实体存储 } DAO获取列表方法 看法 堆栈跟踪 已解决:Hibernate 如何在表单中显示列表中的值(数据库中的值)?,hibernate,list,jsp,spring-mvc,createquery,Hibernate,List,Jsp,Spring Mvc,Createquery,在我的数据库中,我有3个表,显示在图像上。我不想从存储表中获取数据并以表单形式显示。但我的名单有问题。查询在数据库中工作良好,并且在程序中也得到了对象,但不想在窗体上显示。什么问题 实体存储 } DAO获取列表方法 看法 堆栈跟踪 已解决: @Override public List<Store> getAllStoresWithoutCurrentGoods(int userId, int goodsId) throws SQLException { Session s
@Override
public List<Store> getAllStoresWithoutCurrentGoods(int userId, int goodsId) throws SQLException {
Session session = null;
List<Store> stores = new ArrayList<Store>();
try {
session = this.sessionFactory.openSession();
stores = session.createQuery("from Store u where (u.user.id = :userId) and" +
" not exists(from CatalogStore u1 where" +
" (u1.store.id = u.id) and (u1.catalogCompany.id = :goodsId))")
.setParameter("goodsId", goodsId).setParameter("userId", userId).list();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null && session.isOpen())
session.close();
}
return stores;
}
@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)
...
@Override
public List<Store> getAllStoresWithoutCurrentGoods(int userId, int goodsId) throws SQLException {
Session session = null;
List<Store> stores = new ArrayList<Store>();
try {
session = this.sessionFactory.openSession();
stores = session.createQuery("from Store u where (u.user.id = :userId) and" +
" not exists(from CatalogStore u1 where" +
" (u1.store.id = u.id) and (u1.catalogCompany.id = :goodsId))")
.setParameter("goodsId", goodsId).setParameter("userId", userId).list();
} catch (Exception e) {
e.printStackTrace();
} finally {
if (session != null && session.isOpen())
session.close();
}
return stores;
}