CShop Project 09: 显示商品列表所属的商品分类
作者:互联网
1. TypeDao.java
public Type select(int id) throws SQLException{ QueryRunner r = new QueryRunner(DBUtil.getDataSource()); String sql = "select * from type where id = ?"; return r.query(sql, new BeanHandler<Type>(Type.class),id); }
2. TypeService.java
public Type select(int id){ Type t = null; try { t = tDao.select(id); } catch (SQLException e) { e.printStackTrace(); } return t; }
3. GoodsListServlet.java
private TypeService tService = new TypeService(); Type t = null; if(id != 0) { t = tService.select(id); } request.setAttribute("t", t);
4. goods_list.jsp
<h2><c:choose><c:when test="${empty t }">全部系列</c:when><c:otherwise>${t.name }</c:otherwise></c:choose></h2>
效果
标签:CShop,java,09,Project,TypeService,new,Type,id,select 来源: https://www.cnblogs.com/JasperZhao/p/13562982.html