zoukankan      html  css  js  c++  java
  • (九)分类展示上

    最初的设计
            点击首页的时候,查询分类信息

     步骤分析:
          1.创建分类表

          2.在indexservlet上查询分类信息

          3.调用CategoryService.findAll() 返回值是:list

     

    创建分类表

      见http://www.cnblogs.com/Michael2397/p/7633263.html

    创建分类实体

    package com.louis.domain;
    
    public class Category {
        private String cid;
        private String cname;
    
        public String getCid() {
            return cid;
        }
    
        public void setCid(String cid) {
            this.cid = cid;
        }
    
        public String getCname() {
            return cname;
        }
    
        public void setCname(String cname) {
            this.cname = cname;
        }
    }

    创建service

        /*
         * 查询所有的分类
         * */
        public List<Category> findAll() throws Exception {
            CategoryDao categoryDao = new CategoryDaoImpl();
            return categoryDao.findAll();
        }

    创建dao

        @Override
        public List<Category> findAll() throws Exception {
            QueryRunner qr = new QueryRunner(DataSourceUtils.getDataSource());
            String sql="select * from category";
            return qr.query(sql, new BeanListHandler<>(Category.class));
        }

    IndexServlet

    /**
     * 和首页相关的servlet
     */
    public class IndexServlet extends BaseServlet {
        public String index(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //1、调用categoryservice查询所有的分类,返回list
            CategoryService categoryService = new CategoryServiceImpl();
            List<Category> clist =null;
            try {
                clist = categoryService.findAll();
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            //2、将返回值放入request域中
            request.setAttribute("clist", clist);
            // 去数据库中查询最新商品和热门商品,将他们放入request域中请求转发
            return "/jsp/index.jsp";
        }

    前端

    效果

  • 相关阅读:
    验证字符串空“” 的表达式
    should not this be a private conversation
    【转】你真的了解word-wrap 和 word-break 的区别吗
    To live is to function,that is all there is in living
    [转] windows 上用程序putty使用 ssh自动登录Linux(Ubuntu)
    Vim/gvim容易忘记的快捷键
    [转] Gvim for windows中块选择的方法
    问题集
    web services
    Trouble Shooting
  • 原文地址:https://www.cnblogs.com/Michael2397/p/7639725.html
Copyright © 2011-2022 走看看