zoukankan      html  css  js  c++  java
  • CShop Project 08: 开发商品分类的查询和展示

    效果

    0.  Model层中: Type.java

     

    1.  TypeDao.java

    public List<Type> selectAll() throws SQLException{
                QueryRunner r = new QueryRunner(DBUtil.getDataSource());
                String sql = "select * from type";
                return r.query(sql, new BeanListHandler<Type>(Type.class));        
        }

    2.  TypeService.java

    public class TypeService {
        public TypeDao tDao = new TypeDao();
        public List<Type> selectAll(){
            List<Type> list = null;
            try {
                list = tDao.selectAll();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            return list;
        }
    }

    3.  ApplicationListener.java

    @WebListener
    public class ApplicationListener implements ServletContextListener {
    
        private TypeService tService = new TypeService();
    
        public void contextDestroyed(ServletContextEvent arg0)  { 
     
        }
    
    
        public void contextInitialized(ServletContextEvent arg0)  { 
            List<Type> list = tService.selectAll();
            arg0.getServletContext().setAttribute("typeList", list);
        }
        
    }

    4.  header.jsp

          <h4>商品分类</h4>
          <ul class="multi-column-dropdown">
                    <li><a class="list" href="goods.action?typeid=5">全部系列</a></li>
                    <c:forEach items="${typeList }" var="t">
                         <li><a class="list" href="goods.action?typeid=5">${t.name }</a></li>
                    </c:forEach>                                                                                                     
          </ul>
  • 相关阅读:
    逝华
    数论知识
    #10081. 「一本通 3.2 练习 7」道路和航线 题解
    Tire 字典树
    Manacher算法
    时间变奏曲
    【算法】莫队
    【算法】深度优先搜索(dfs)
    【算法】数位 dp
    【笔记】关于位运算(2)
  • 原文地址:https://www.cnblogs.com/JasperZhao/p/13553043.html
Copyright © 2011-2022 走看看