一、请简述你设计的商品列表功能。

1.该功能创建了几张表,每个表的功能是什么,并介绍下主要字段和作用?

recommend表对应商品自动滑动的,表里包含自身的id和蛋糕goods的id,蛋糕所属类别的id;

type表对应蛋糕所属类别的id和名称;

goods表对应所有商品的内容,包含商品id,名称,商品图片,商品价格,商品介绍,商品库存,蛋糕所属类别id;

2.简要说明实现该功能。比如:创建了几个类,并介绍功能、算法逻辑、实现代码。

算法实现:

首先登录蛋糕商城首页是通过index.jsp展示的,其中的目录是通过引入header.jsp,底部联系网址是通过引入footer.jsp;页面的蛋糕内容是通过IndexServlet.class类中doGet方法来获取数据库内容(其中IndexServlet类是用来填写数据,GoodsService类是实现数据库每一条语句对应一个方法,相当于mybatis中的接口,GoodsDao类是实现GoodsService中的方法),然后填充到页面中,再通过index.jsp进行展示实现的;

关键代码:

List> ScrollGood=gService.getScrollGood();

request.setAttribute("scroll",ScrollGood);List>newList=gService.getGoodsList(3);request.setAttribute("newList",newList);List>hotList=gService.getGoodsList(2);

request.setAttribute("hotList",hotList);//response.sendRedirect("index.jsp");request.getRequestDispatcher("index.jsp").forward(request,response);

Goods类实现goods实例化;

public class Goods {

   private int id;    private String name;    private String cover;    private String image1;    private String image2;    private float price;    private String intro;    private int stock;    private Type type;       private boolean isScroll;    private boolean isHot;    private boolean isNew;          public boolean getIsScroll() {       return isScroll;    }    public void setScroll(boolean isScroll) {       this.isScroll = isScroll;    }    public boolean getIsHot() {       return isHot;    }    public void setHot(boolean isHot) {       this.isHot = isHot;    }    public boolean getIsNew() {       return isNew;    }    public void setNew(boolean isNew) {       this.isNew = isNew;    }    public void setTypeid(int typeid) {       if(type==null) {          type = new Type();       }       type.setId(typeid);    }    public void setTypename(String typename) {       if(type==null) {          type = new Type();       }       type.setName(typename);    }    @Override    public String toString() {       return "Goods [id=" + id + ", name=" + name + ", cover=" + cover + ", image1=" + image1 + ", image2=" + image2             + ", price=" + price + ", intro=" + intro + ", stock=" + stock + ", type=" + type + "]";    }    public int getId() {       return id;    }    public void setId(int id) {       this.id = id;    }    public String getName() {       return name;    }    public void setName(String name) {       this.name = name;    }    public String getCover() {       return cover;    }    public void setCover(String cover) {       this.cover = cover;    }    public String getImage1() {       return image1;    }    public void setImage1(String image1) {       this.image1 = image1;    }    public String getImage2() {       return image2;    }    public void setImage2(String image2) {       this.image2 = image2;    }    public float getPrice() {       return price;    }    public void setPrice(float price) {       this.price = price;    }    public String getIntro() {       return intro;    }    public void setIntro(String intro) {       this.intro = intro;    }    public int getStock() {       return stock;    }    public void setStock(int stock) {       this.stock = stock;    }    public Type getType() {       return type;    }    public void setType(Type type) {       this.type = type;    }    public Goods() {       super();    }    public Goods(int id, String name, String cover, String image1, String image2, float price, String intro, int stock,          Type type) {       super();       this.id = id;       this.name = name;       this.cover = cover;       this.image1 = image1;       this.image2 = image2;       this.price = price;       this.intro = intro;       this.stock = stock;       this.type = type;    }       }

Recommend类实现recommend表实例化;

public class Recommend {

   private int id;    private int type;//1条幅 2热销 3新品    private Goods goods;    public int getId() {       return id;    }    public void setId(int id) {       this.id = id;    }    public int getType() {       return type;    }    public void setType(int type) {       this.type = type;    }    public Goods getGoods() {       return goods;    }    public void setGoods(Goods goods) {       this.goods = goods;    }    public Recommend(int id, int type, Goods goods) {       super();       this.id = id;       this.type = type;       this.goods = goods;    }    public Recommend() {       super();    }       }

Type类实现type表的实例化;

import java.io.UnsupportedEncodingException;

import java.net.URLEncoder; public class Type {    private int id;    private String name;       private String encodeName;       public String getEncodeName() {       return encodeName;    }    public void setEncodeName(String encodeName) {       this.encodeName = encodeName;    }    public int getId() {       return id;    }    public void setId(int id) {       this.id = id;    }    public String getName() {       return name;    }    public void setName(String name) {       this.name = name;       try {          this.encodeName = URLEncoder.encode(name, "utf-8");       } catch (UnsupportedEncodingException e) {          // TODO Auto-generated catch block          e.printStackTrace();       }    }    public Type(int id, String name) {       super();       this.id = id;       this.name = name;    }    public Type() {       super();    }    public Type(String name) {       super();       this.name = name;    }    }

GoodsDao类实现对goods表的进行增删改查;

import model.Goods;

import model.Recommend; import org.apache.commons.dbutils.*; import org.apache.commons.dbutils.handlers.*; import utils.DataSourceUtils; import java.sql.SQLException; import java.util.*; public class GoodsDao {     //select g.id,g.name,g.cover,g.price,t.name typename from recommend r,goods g,type t where type=2 and r.goods_id=g.id and g.type_id=t.id     public List> getGoodsList(int recommendType) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql="select g.id,g.name,g.cover,g.price,t.name typename from recommend r,goods g,type t where type=? and r.goods_id=g.id and g.type_id=t.id";         return r.query(sql, new MapListHandler(),recommendType);     }     public List> getScrollGood()throws SQLException{         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());//        String sql="select g.id,g.name,g.cover,g.price  from recommend r,goods g where type=1 and r.goods_id=g.id"; //        return r.query(sql, new MapHandler());         String sql="select g.id,g.name,g.cover,g.price  from recommend r,goods g where r.goods_id=g.id";         return r.query(sql, new MapListHandler());     }     public List selectGoodsByTypeID(int typeID,int pageNumber,int pageSize) throws SQLException {         if(typeID==0)         {             String sql="select * from goods limit ? , ?";             QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());             return  r.query(sql,new BeanListHandler(Goods.class),(pageNumber-1)*pageSize,pageSize);         }         else         {             String sql="select * from goods where type_id=? limit ? , ?";             QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());             return  r.query(sql,new BeanListHandler(Goods.class),typeID,(pageNumber-1)*pageSize,pageSize);         }     }     public int getCountOfGoodsByTypeID(int typeID) throws SQLException {         String sql="";         QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());         if(typeID==0)         {             sql="select count(*) from goods";             return r.query(sql,new ScalarHandler()).intValue();         }         else         {             sql="select count(*) from goods where type_id=?";             return r.query(sql,new ScalarHandler(),typeID).intValue();         }     }     public List selectGoodsbyRecommend(int type,int pageNumber,int pageSize) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         if(type==0) {             //当不添加推荐类型限制的时候             String sql = " select g.id,g.name,g.cover,g.image1,g.image2,g.intro,g.price,g.stock,t.name typename from goods g,type t where g.type_id=t.id order by g.id limit ?,?";             return r.query(sql, new BeanListHandler(Goods.class),(pageNumber-1)*pageSize,pageSize);         }         String sql = " select g.id,g.name,g.cover,g.image1,g.image2,g.intro,g.price,g.stock,t.name typename from goods g,recommend r,type t where g.id=r.goods_id and g.type_id=t.id and r.type=? order by g.id limit ?,?";         return r.query(sql, new BeanListHandler(Goods.class),type,(pageNumber-1)*pageSize,pageSize);     }     public int getRecommendCountOfGoodsByTypeID(int type) throws SQLException {         if(type==0)return getCountOfGoodsByTypeID(0);         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "select count(*) from recommend where type=?";         return r.query(sql, new ScalarHandler(),type).intValue();     }     public Goods getGoodsById(int id) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "select g.id,g.name,g.cover,g.image1,g.image2,g.price,g.intro,g.stock,t.id typeid,t.name typename from goods g,type t where g.id = ? and g.type_id=t.id";         return r.query(sql, new BeanHandler(Goods.class),id);     }     public int getSearchCount(String keyword) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "select count(*) from goods where name like ?";         return r.query(sql, new ScalarHandler(),"%"+keyword+"%").intValue();     }     public List selectSearchGoods(String keyword, int pageNumber, int pageSize) throws SQLException{         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "select * from goods where name like ? limit ?,?";         return r.query(sql, new BeanListHandler(Goods.class),"%"+keyword+"%",(pageNumber-1)*pageSize,pageSize);     }     public boolean isScroll(Goods g) throws SQLException {         return isRecommend(g, 1);     }     public boolean isHot(Goods g) throws SQLException {         return isRecommend(g, 2);     }     public boolean isNew(Goods g) throws SQLException {         return isRecommend(g, 3);     }     private boolean isRecommend(Goods g,int type) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "select * from recommend where type=? and goods_id=?";         Recommend recommend = r.query(sql, new BeanHandler(Recommend.class),type,g.getId());         if(recommend==null) {             return false;         }else {             return true;         }     }     public void addRecommend(int id,int type) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "insert into recommend(type,goods_id) values(?,?)";         r.update(sql,type,id);     }     public void removeRecommend(int id,int type) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "delete from recommend where type=? and goods_id=?";         r.update(sql,type,id);     }     public void insert(Goods g) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "insert into goods(name,cover,image1,image2,price,intro,stock,type_id) values(?,?,?,?,?,?,?,?)";         r.update(sql,g.getName(),g.getCover(),g.getImage1(),g.getImage2(),g.getPrice(),g.getIntro(),g.getStock(),g.getType().getId());     }     public void update(Goods g) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "update goods set name=?,cover=?,image1=?,image2=?,price=?,intro=?,stock=?,type_id=? where id=?";         r.update(sql,g.getName(),g.getCover(),g.getImage1(),g.getImage2(),g.getPrice(),g.getIntro(),g.getStock(),g.getType().getId(),g.getId());     }     public void delete(int id) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "delete from goods where id = ?";         r.update(sql,id);     } }

TypeDao类实现对type表的增上改查来辅助GoodsDao更好的对goods类别的分类;

import model.Type;

import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.BeanHandler; import org.apache.commons.dbutils.handlers.BeanListHandler; import utils.DataSourceUtils; import java.sql.SQLException; import java.util.List; public class TypeDao {     public List GetAllType() throws SQLException {         QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());         String sql="select * from type";         return r.query(sql,new BeanListHandler(Type.class));     }     public Type selectTypeNameByID(int typeid) throws SQLException {         QueryRunner r=new QueryRunner(DataSourceUtils.getDataSource());         String sql="select * from type where id=?";         return r.query(sql,new BeanHandler(Type.class),typeid);     }     public Type select(int id) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "select * from type where id = ?";         return r.query(sql, new BeanHandler(Type.class),id);     }     public void insert(Type t) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "insert into type(name) values(?)";         r.update(sql,t.getName());     }     public void update(Type t) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "update type set name=? where id = ?";         r.update(sql,t.getName(),t.getId());     }     public void delete(int id) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "delete from type where id = ?";         r.update(sql,id);     } }

Index.jsp蛋糕商城的首页,展示蛋糕种类;

<%@ page contentType="text/html;charset=UTF-8"

language="java" %><%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><%     String path=request.getContextPath();     String basePath=request.getScheme()+"://"+request.getServerName()+":8080"+path+"/"; %>     商品列表                                        

footer.jsp商城页面最下面内容显示

<%@ page contentType="text/html;charset=UTF-8"

language="java" %>

header.jsp实现蛋糕商城首页上面目录显示;

<%@ page contentType="text/html;charset=UTF-8"

language="java" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><%--   Created by IntelliJ IDEA.   User: 19767   Date: 2018/11/23   Time: 15:49   To change this template use File | Settings | File Templates. --%>

   
               
                                   
       
       
   

3.该商品列表运行截图。

1.普通用户

首页

 

用户登录

购物车

支付

2.管理员登录

首页

订单管理

客户管理

商品管理

类型管理

二、请简述你设计的订单功能。

1.该功能创建了几张表,每个表的功能是什么,并介绍下主要字段和作用?

User表实现用户和管理员登录的账号;username用户登录名,password登录密码,name用户属性,phone电话号码,adress用户收货地址,isadmin是否为管理员;

Order表管理员对用户订单的管理,total表示订单总价格,amount一个订单蛋糕数量,status表示用户订单是否发货,paytype用户支付类型,name收货人名字,phone收货人电话,adress收货地址,datetime购买时间,user_id购买人的id;

Orderitem表实现用户订单和管理员订单内容管理;prince订单中蛋糕的价格,amount蛋糕购买的数量,goods_id商品的id,order_id订单的id。

2.简要说明实现该功能。比如:创建了几个类,并介绍功能、算法逻辑、实现代码。

算法实现

用户订单

Order类对订单属性的实例化;OrderListServlet类首先获取页面中用户的id,如果没有出现登录界面;然后通过OrderService类中的方法来获取OrderDao中的sql语句查询数据库的信息来填写页面的内容,然后跳转到订单界面。

管理员订单

Page类管理订单页面;AdminOrderListServlet类首先判断用户的订单是否发货,然后通过OrderService类中的方法来获取OrderDao中的sql语句查询数据库的信息来填写页面的内容,然后跳转到订单管理界面。

3.该订单运行截图。

用户订单

管理员订单

代码

Page.class

import java.util.List;

public class Page {     private int pageNumber;     private int pageSize;     private int totalCount;     private int totalPage;     private List list;     public void SetPageSizeAndTotalCount(int pageSize,int totalCount)     {         this.pageSize=pageSize;         this.totalCount=totalCount;         totalPage= (int)Math.ceil((double)totalCount/pageSize);     }     public int getPageNumber() {         return pageNumber;     }     public void setPageNumber(int pageNumber) {         this.pageNumber = pageNumber;     }     public int getPageSize() {         return pageSize;     }     public void setPageSize(int pageSize) {         this.pageSize = pageSize;     }     public int getTotalCount() {         return totalCount;     }     public void setTotalCount(int totalCount) {         this.totalCount = totalCount;     }     public int getTotalPage() {         return totalPage;     }     public void setTotalPage(int totalPage) {         this.totalPage = totalPage;     }     public List getList() {         return list;     }     public void setList(List list) {         this.list = list;     } }

AdminOrderListServlet.class

import model.Page;

import service.OrderService; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;@WebServlet(name = "admin_order_list",urlPatterns = "/admin/order_list")public class AdminOrderListServlet extends HttpServlet {     private OrderService oService = new OrderService();     /**      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)      */     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {         int status = 0;         if(request.getParameter("status") != null) {             status=Integer.parseInt(request.getParameter("status") ) ;         }         request.setAttribute("status", status);         int pageNumber = 1;         if(request.getParameter("pageNumber") != null) {             try {                 pageNumber=Integer.parseInt(request.getParameter("pageNumber") ) ;             }             catch (Exception e)             {             }         }         if(pageNumber<=0)             pageNumber=1;         Page p = oService.getOrderPage(status,pageNumber);         if(p.getTotalPage()==0)         {             p.setTotalPage(1);             p.setPageNumber(1);         }         else {             if(pageNumber>=p.getTotalPage()+1)             {                 p = oService.getOrderPage(status,pageNumber);             }         }         request.setAttribute("p", p);         request.getRequestDispatcher("/admin/order_list.jsp").forward(request, response);     } }

OrderService.class

import dao.*;

import model.*; import utils.*; import java.sql.*; import java.util.List; public class OrderService {     private OrderDao oDao = new OrderDao();     public void addOrder(Order order) {         Connection con = null;         try {             con = DataSourceUtils.getConnection();             con.setAutoCommit(false);             oDao.insertOrder(con, order);             int id = oDao.getLastInsertId(con);             order.setId(id);             for(OrderItem item : order.getItemMap().values()) {                 oDao.insertOrderItem(con, item);             }             con.commit();         } catch (SQLException e) {             // TODO Auto-generated catch block             e.printStackTrace();             if(con!=null)                 try {                     con.rollback();                 } catch (SQLException e1) {                     // TODO Auto-generated catch block                     e1.printStackTrace();                 }         }     }     public List selectAll(int userid){         List list=null;         try {             list = oDao.selectAll(userid);             for(Order o :list) {                 List l = oDao.selectAllItem(o.getId());                 o.setItemList(l);             }         } catch (SQLException e) {             // TODO Auto-generated catch block             e.printStackTrace();         }         return list;     }     public Page getOrderPage(int status,int pageNumber) {         Page p = new Page();         p.setPageNumber(pageNumber);         int pageSize = 10;         int totalCount = 0;         try {             totalCount = oDao.getOrderCount(status);         } catch (SQLException e) {             // TODO Auto-generated catch block             e.printStackTrace();         }         p.SetPageSizeAndTotalCount(pageSize, totalCount);         List list=null;         try {             list = oDao.selectOrderList(status, pageNumber, pageSize);             for(Order o :(List)list) {                 List l = oDao.selectAllItem(o.getId());                 o.setItemList(l);             }         } catch (SQLException e) {             // TODO Auto-generated catch block             e.printStackTrace();         }         p.setList(list);         return p;     }     public void updateStatus(int id,int status) {         try {             oDao.updateStatus(id, status);         } catch (SQLException e) {             // TODO Auto-generated catch block             e.printStackTrace();         }     }     public void delete(int id) {         Connection con = null;         try {             con = DataSourceUtils.getDataSource().getConnection();             con.setAutoCommit(false);             oDao.deleteOrderItem(con, id);             oDao.deleteOrder(con, id);             con.commit();         } catch (SQLException e) {             // TODO Auto-generated catch block             e.printStackTrace();             if(con!=null)                 try {                     con.rollback();                 } catch (SQLException e1) {                     // TODO Auto-generated catch block                     e1.printStackTrace();                 }         }     } }

OrderDao.class

import model.*;

import org.apache.commons.dbutils.*; import utils.*; import java.math.*; import java.sql.*; import java.util.*; import org.apache.commons.dbutils.handlers.*; public class OrderDao {     public void insertOrder(Connection con, Order order) throws SQLException {         QueryRunner r = new QueryRunner();         String sql = "insert into `order`(total,amount,status,paytype,name,phone,address,datetime,user_id) values(?,?,?,?,?,?,?,?,?)";         r.update(con,sql,                 order.getTotal(),order.getAmount(),order.getStatus(),                 order.getPaytype(),order.getName(),order.getPhone(),                 order.getAddress(),order.getDatetime(),order.getUser().getId() );     }     public int getLastInsertId(Connection con) throws SQLException {         QueryRunner r = new QueryRunner();         String sql = "select last_insert_id()";         BigInteger bi = r.query(con, sql,new ScalarHandler());         return Integer.parseInt(bi.toString());     }     public void insertOrderItem(Connection con, OrderItem item) throws SQLException {         QueryRunner r = new QueryRunner();         String sql ="insert into orderitem(price,amount,goods_id,order_id) values(?,?,?,?)";         r.update(con,sql,item.getPrice(),item.getAmount(),item.getGoods().getId(),item.getOrder().getId());     }     public List selectAll(int userid) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "select * from `order` where user_id=? order by datetime desc";         return r.query(sql, new BeanListHandler(Order.class),userid);     }     public List selectAllItem(int orderid) throws SQLException{         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "select i.id,i.price,i.amount,g.name from orderitem i,goods g where order_id=? and i.goods_id=g.id";         return r.query(sql, new BeanListHandler(OrderItem.class),orderid);     }     public int getOrderCount(int status) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql = "";         if(status==0) {             sql = "select count(*) from `order`";             return r.query(sql, new ScalarHandler()).intValue();         }else {             sql = "select count(*) from `order` where status=?";             return r.query(sql, new ScalarHandler(),status).intValue();         }     }     public List selectOrderList(int status, int pageNumber, int pageSize) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         if(status==0) {             String sql = "select o.id,o.total,o.amount,o.status,o.paytype,o.name,o.phone,o.address,o.datetime,u.username from `order` o,user u where o.user_id=u.id order by o.datetime desc limit ?,?";             return r.query(sql, new BeanListHandler(Order.class), (pageNumber-1)*pageSize,pageSize );         }else {             String sql = "select o.id,o.total,o.amount,o.status,o.paytype,o.name,o.phone,o.address,o.datetime,u.username from `order` o,user u where o.user_id=u.id and o.status=? order by o.datetime desc limit ?,?";             return r.query(sql, new BeanListHandler(Order.class),status, (pageNumber-1)*pageSize,pageSize );         }     }     public void updateStatus(int id,int status) throws SQLException {         QueryRunner r = new QueryRunner(DataSourceUtils.getDataSource());         String sql ="update `order` set status=? where id = ?";         r.update(sql,status,id);     }     public void deleteOrder(Connection con ,int id) throws SQLException {         QueryRunner r = new QueryRunner();         String sql ="delete from `order` where id = ?";         r.update(con,sql,id);     }     public void deleteOrderItem(Connection con ,int id) throws SQLException {         QueryRunner r = new QueryRunner();         String sql ="delete from orderitem where order_id=?";         r.update(con,sql,id);     } }

order_list.jsp

<%@ page contentType="text/html;charset=UTF-8"

language="java" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>    我的订单                                                         

     
                          

我的订单

                                                                                                                                                                                                                                                                                                                                                                                         
ID总价商品详情收货信息订单状态支付方式下单时间

${order.id }

${order.total }

                                                    

${item.goodsName }(${item.price }) x ${item.amount }

                       
                    
                        

${order.name }

                       

${order.phone }

                       

${order.address }

                    
                       

                           已付款                           已发货                           已完成                        

                    
                       

                           微信                           支付宝                           货到付款                        

                    

${order.datetime }

                                         
  
                     

admin/order_list

<%@ page contentType="text/html;charset=UTF-8"

language="java" %><%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 订单列表

        
     
                                                                                                                                                                                                                    
ID总价商品详情收货信息订单状态支付方式下单用户下单时间操作

${order.id }

${order.total }

                                

${item.goodsName }(${item.price }) x ${item.amount}

               
           
              

${order.name }

              

${order.phone }

              

${order.address }

           
              

                  已付款                  已发货                  已完成                

           
              

                  微信                  支付宝                  货到付款               

           

${order.user.username }

${order.datetime }

                                  发货                                                 完成                                删除            

                 

三、请简要描述过滤器拦截登录的核心代码,以及过滤器类的配置文件。

AdminFilter.class类拦截用户直接通过输入url进入管理员页面,如果通过url访问admin/…会进行拦截,判断是否有用户,如果没有进入index.jsp页面,否则将请求转发给过滤器链上下一个对象。

import model.User;

import javax.servlet.*; import javax.servlet.annotation.WebFilter; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException;@WebFilter(filterName = "AdminFilter",urlPatterns = "/admin/*")public class AdminFilter implements Filter {     public void destroy() {     }     public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {         HttpServletRequest request = (HttpServletRequest)req;         HttpServletResponse requestp = (HttpServletResponse)resp;         User u = (User) request.getSession().getAttribute("user");         if(u==null || u.isIsadmin()==false) {             requestp.sendRedirect("../index.jsp");         }else {             // pass the request along the filter chain             chain.doFilter(req, resp);         }     }     public void init(FilterConfig config) throws ServletException {     } }

EncodeFilter.class过滤器实现对所有的页面内容经行utf-8编码;

import javax.servlet.*;

import javax.servlet.annotation.WebFilter; import java.io.IOException;@WebFilter(filterName = "EncodeFilter",urlPatterns = "/*")public class EncodeFilter implements Filter {     public void destroy() {     }     public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws ServletException, IOException {         req.setCharacterEncoding("utf-8");         chain.doFilter(req, resp);     }     public void init(FilterConfig config) throws ServletException {     } }

四、请简要该系统中使用MVC模式分别如何封装,用到了什么框架,并举例说明一下你是如何封装查询商品列表功能的?

module包中的类是对数据库表的属性进行封装,和其他页面需要展示的数据类型封装。

dao包中的类是对数据库的操作的语句,每一条语句对应一个方法,然后把结果返回到servlet包中的类。

Service包中的类是将查询到的内容以对象的方式保存在request作用域中,然后在转发进入的页面。

Servlet包中的类是sql语句对应的方法,类似于mybatis中的接口,主要负责对实现sql语句后的数据进行保存特殊的形式,如list,实例化对象等。

Web包向用户页面展示页面。

本项目使用MVC的思想设计架构,使用Servlet获取和发送请求,Filter拦截请求,通过jsp进行页面展示。

举例:如图获取全部系列的蛋糕具体步骤如下

首先通过首页index.jsp(实际为header.jsp的内容,只是被引用了)目录单击商品分类,出现下拉菜单栏,再点击全部系列,会跳转到GoodsListServlet类中,(这里只举内容,不考虑客户登录和分页)GoodsListServlet类通过调用GoodsService类中的selectPageByTypeId方法,selectPageByTypeId方法再去调用GoodsDao中的getCountOfGoodsByTypeID去获取数据库的内容,内容以对象的方式保存在request作用域中,然后在转发进入的页面,通过goods_list页面展示数据。

 

推荐文章

评论可见,请评论后查看内容,谢谢!!!
 您阅读本篇文章共花了: 

发表评论

返回顶部暗黑模式