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>

效果

 

posted @ 2020-08-26 05:56  Jasper2003  阅读(177)  评论(0编辑  收藏  举报