jsp+servlet+mysql实现的在线鲜花商城

 

jsp+servlet+mysql实现的在线鲜花商城

JDK:jdk1.8

ida:eclipse

数据库:mysql开发环境:
Eclipse ,MYSQL,JDK1.8,Tomcat 8.5
涉及技术点:
MVC模式、SpringBoot、Mybatis、Redis、HTML、log4j、druid、Bootstrap、
Semantic UI、Thymeleaf、JavaScript、CSS、JQUERY、Ajax等
适合学习J2EE的一段时间的熟手,代码思路清晰,注解详细,数据库用的是mysql5.1,服务器用的tomcat8.5,JDK版本1.8. 编程软件Eclispe J2EE版本。是典型MVC架构,并且前后台分离
主要功能:

代码已经上传github,下载地址: https://github.com/21503882/network-flower

jsp+servlet+mysql实现的在线鲜花商城_第1张图片

jsp+servlet+mysql实现的在线鲜花商城_第2张图片

jsp+servlet+mysql实现的在线鲜花商城_第3张图片

jsp+servlet+mysql实现的在线鲜花商城_第4张图片

jsp+servlet+mysql实现的在线鲜花商城_第5张图片

jsp+servlet+mysql实现的在线鲜花商城_第6张图片

jsp+servlet+mysql实现的在线鲜花商城_第7张图片

jsp+servlet+mysql实现的在线鲜花商城_第8张图片

jsp+servlet+mysql实现的在线鲜花商城_第9张图片

jsp+servlet+mysql实现的在线鲜花商城_第10张图片

jsp+servlet+mysql实现的在线鲜花商城_第11张图片

jsp+servlet+mysql实现的在线鲜花商城_第12张图片

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.hr.entity.EASYBUY_PRODUCT;

public class EASYBUY_PRODUCTDao {
    
    
    
    /**
     * 查询所有
     * @return
     */


    public static ArrayList selectAll(){
        ArrayList list = new ArrayList();
        ResultSet rs = null;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement("select * from EASYBUY_PRODUCT");
            rs = ps.executeQuery();
            while(rs.next()){
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                                        rs.getString("EP_NAME"), 
                                        rs.getString("EP_DESCRIPTION"),
                                        rs.getInt("EP_PRICE"),
                                        rs.getInt("EP_STOCK"),
                                        rs.getInt("EPC_ID"),
                                        rs.getInt("EPC_CHILD_ID"),
                                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            Basedao.closeall(rs, ps, conn);
        }
        return list;
    }
    


    /**


     * 名字模糊查询
     * @return
     */
    public static ArrayList selectAllByName(String name){
        ArrayList list = new ArrayList();
        ResultSet rs = null;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement("select * from EASYBUY_PRODUCT where EP_NAME like ?");
            ps.setString(1, "%"+name+"%");
            rs = ps.executeQuery();
            while(rs.next()){
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                                        rs.getString("EP_NAME"), 
                                        rs.getString("EP_DESCRIPTION"),
                                        rs.getInt("EP_PRICE"),
                                        rs.getInt("EP_STOCK"),
                                        rs.getInt("EPC_ID"),
                                        rs.getInt("EPC_CHILD_ID"),
                                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            Basedao.closeall(rs, ps, conn);
        }
        return list;
    }


    /**
     * 根据id查询单个
     * @param id
     * @return
     */
    public static EASYBUY_PRODUCT selectById(int id){
        EASYBUY_PRODUCT p = null;
        ResultSet rs = null;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement("select * from EASYBUY_PRODUCT where EP_ID=?");
            ps.setInt(1, id);
            rs = ps.executeQuery();
            while(rs.next()){
                p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                        rs.getString("EP_NAME"), 
                        rs.getString("EP_DESCRIPTION"),
                        rs.getInt("EP_PRICE"),
                        rs.getInt("EP_STOCK"),
                        rs.getInt("EPC_ID"),
                        rs.getInt("EPC_CHILD_ID"),
                        rs.getString("EP_FILE_NAME"));
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            Basedao.closeall(rs, ps, conn);
        }
        return p;
    }
    
    /**
     * 根据fid查询所有
     * @param fid
     * @return
     */
    public static ArrayList selectAllByFid(int fid){
        ArrayList list = new ArrayList();
        ResultSet rs = null;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement("select * from EASYBUY_PRODUCT where EPC_ID=?");
            ps.setInt(1, fid);
            rs = ps.executeQuery();
            while(rs.next()){
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                                        rs.getString("EP_NAME"), 
                                        rs.getString("EP_DESCRIPTION"),
                                        rs.getInt("EP_PRICE"),
                                        rs.getInt("EP_STOCK"),
                                        rs.getInt("EPC_ID"),
                                        rs.getInt("EPC_CHILD_ID"),
                                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            Basedao.closeall(rs, ps, conn);
        }
        return list;
    }
    
    /**
     * 根据cid查询所有
     * @param fid
     * @return
     */
    public static ArrayList selectAllByCid(int cid){
        ArrayList list = new ArrayList();
        ResultSet rs = null;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        try {
            ps = conn.prepareStatement("select * from EASYBUY_PRODUCT where EPC_CHILD_ID=?");
            ps.setInt(1, cid);
            rs = ps.executeQuery();
            while(rs.next()){
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                                        rs.getString("EP_NAME"), 
                                        rs.getString("EP_DESCRIPTION"),
                                        rs.getInt("EP_PRICE"),
                                        rs.getInt("EP_STOCK"),
                                        rs.getInt("EPC_ID"),
                                        rs.getInt("EPC_CHILD_ID"),
                                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            Basedao.closeall(rs, ps, conn);
        }
        return list;
    }
    
    public static int insert(EASYBUY_PRODUCT p){
        String sql = "insert into EASYBUY_PRODUCT values(null,?,?,?,?,?,?,?)";
        Object[] params = {p.getEP_NAME(),
                            p.getEP_DESCRIPTION(),
                            p.getEP_PRICE(),
                            p.getEP_STOCK(),
                            p.getEPC_ID(),
                            p.getEPC_CHILD_ID(),
                            p.getEP_FILE_NAME()};
        return Basedao.exectuIUD(sql, params);
    }
    
    public static int update(EASYBUY_PRODUCT p){
        if(!p.getEP_FILE_NAME().equals("")){
            String sql = "update EASYBUY_PRODUCT set EP_NAME=?," +
                                            "EP_DESCRIPTION=?," +
                                            "EP_PRICE=?," +
                                            "EP_STOCK=?," +
                                            "EPC_ID=?," +
                                            "EPC_CHILD_ID=?," +
                                            "EP_FILE_NAME=? " +
                                            " where EP_ID=?";
         
         Object[] params = {p.getEP_NAME(),
                    p.getEP_DESCRIPTION(),
                    p.getEP_PRICE(),
                    p.getEP_STOCK(),
                    p.getEPC_ID(),
                    p.getEPC_CHILD_ID(),
                    p.getEP_FILE_NAME(),
                    p.getEP_ID()};
         return Basedao.exectuIUD(sql, params);
        }else{
            String     sql = "update EASYBUY_PRODUCT set EP_NAME=?," +
                                                "EP_DESCRIPTION=?," +
                                                "EP_PRICE=?," +
                                                "EP_STOCK=?," +
                                                "EPC_ID=?," +
                                                "EPC_CHILD_ID=? " +
                                                " where EP_ID=?";
             Object[] params = {p.getEP_NAME(),
                        p.getEP_DESCRIPTION(),
                        p.getEP_PRICE(),
                        p.getEP_STOCK(),
                        p.getEPC_ID(),
                        p.getEPC_CHILD_ID(),
                        p.getEP_ID()};
             return Basedao.exectuIUD(sql, params);
        }
        
        
    }
    
    public static int del(int id){
        String sql = "delete from EASYBUY_PRODUCT where EP_ID=?";
        Object[] params = {id};
        return Basedao.exectuIUD(sql, params);
    }
    
    public static int totalPage(int count){
        int tpage = 1;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement("select count(*) from EASYBUY_PRODUCT");
            rs = ps.executeQuery();
            if(rs.next()){
                int sum = rs.getInt(1);//获得表的总行数
                if(sum%count==0){
                    tpage = sum/count;//总行数是每页行数的整倍数
                }else {
                    tpage = sum/count+1;//不是整倍数要加一
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        return tpage;
    }
    
    public static int totalPageByFid(int count,int fid){
        int tpage = 1;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement("select count(*) from EASYBUY_PRODUCT where EPC_ID=?");
            ps.setInt(1, fid);
            rs = ps.executeQuery();
            if(rs.next()){
                int sum = rs.getInt(1);//获得表的总行数
                if(sum%count==0){
                    tpage = sum/count;//总行数是每页行数的整倍数
                }else {
                    tpage = sum/count+1;//不是整倍数要加一
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        return tpage;
    }
    
    public static int totalPageByCid(int count,int cid){
        int tpage = 1;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement("select count(*) from EASYBUY_PRODUCT where EPC_CHILD_ID=?");
            ps.setInt(1, cid);
            rs = ps.executeQuery();
            if(rs.next()){
                int sum = rs.getInt(1);//获得表的总行数
                if(sum%count==0){
                    tpage = sum/count;//总行数是每页行数的整倍数
                }else {
                    tpage = sum/count+1;//不是整倍数要加一
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        return tpage;
    }
    
    public static int totalPageByName(int count,String name){
        int tpage = 1;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
            ps = conn.prepareStatement("select count(*) from EASYBUY_PRODUCT where EP_NAME like ?");
            ps.setString(1, "%"+name+"%");
            rs = ps.executeQuery();
            if(rs.next()){
                int sum = rs.getInt(1);//获得表的总行数
                if(sum%count==0){
                    tpage = sum/count;//总行数是每页行数的整倍数
                }else {
                    tpage = sum/count+1;//不是整倍数要加一
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        return tpage;
    }
    /**
     * 分页查询
     * @param cpage
     * @param count
     * @return
     */
    public static ArrayList selectAll(int cpage,int count){
        ArrayList list = new ArrayList();
        Connection conn =Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from EASYBUY_PRODUCT order by EP_ID desc limit ?,? ";
        try {
            ps = conn.prepareStatement(sql);
            //设置数据区间
            ps.setInt(1, count*(cpage-1));
            ps.setInt(2, count);
            rs = ps.executeQuery();
            while(rs.next()) {
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                        rs.getString("EP_NAME"), 
                        rs.getString("EP_DESCRIPTION"),
                        rs.getInt("EP_PRICE"),
                        rs.getInt("EP_STOCK"),
                        rs.getInt("EPC_ID"),
                        rs.getInt("EPC_CHILD_ID"),
                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        
        return list;
    }
    /**
     * fid分页查询
     * @param cpage
     * @param count
     * @return
     */
    public static ArrayList selectAllByFid(int cpage,int count,int fid){
        ArrayList list = new ArrayList();
        Connection conn =Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from EASYBUY_PRODUCT where EPC_ID = ? order by EP_ID desc limit ?,?";
        try {
            ps = conn.prepareStatement(sql);
            //设置数据区间
            ps.setInt(1, fid);
            ps.setInt(2, count*(cpage-1));
            ps.setInt(3, count);
            rs = ps.executeQuery();
            while(rs.next()) {
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                        rs.getString("EP_NAME"), 
                        rs.getString("EP_DESCRIPTION"),
                        rs.getInt("EP_PRICE"),
                        rs.getInt("EP_STOCK"),
                        rs.getInt("EPC_ID"),
                        rs.getInt("EPC_CHILD_ID"),
                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        
        return list;
    }
    
    /**
     * cid分页查询
     * @param cpage
     * @param count
     * @return
     */
    public static ArrayList selectAllByCid(int cpage,int count,int cid){
        ArrayList list = new ArrayList();
        Connection conn =Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from EASYBUY_PRODUCT where EPC_CHILD_ID = ? order by EP_ID desc limit ?,?";
        try {
            ps = conn.prepareStatement(sql);
            //设置数据区间
            ps.setInt(1, cid);
            ps.setInt(2, count*(cpage-1));
            ps.setInt(3, count);
            rs = ps.executeQuery();
            while(rs.next()) {
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                        rs.getString("EP_NAME"), 
                        rs.getString("EP_DESCRIPTION"),
                        rs.getInt("EP_PRICE"),
                        rs.getInt("EP_STOCK"),
                        rs.getInt("EPC_ID"),
                        rs.getInt("EPC_CHILD_ID"),
                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        
        return list;
    }
    
    /**
     * 根据id数组查询单个,并放入集合
     * @param id
     * @return
     */
    public static ArrayList selectById(ArrayList ids){
        ArrayList lastlylist = new ArrayList();
        EASYBUY_PRODUCT p = null;
        ResultSet rs = null;
        Connection conn = Basedao.getconn();
        PreparedStatement ps = null;
        try {
            for(int i=0;i                 ps = conn.prepareStatement("select * from EASYBUY_PRODUCT where EP_ID=?");
                ps.setInt(1, ids.get(i));
                rs = ps.executeQuery();
                while(rs.next()){
                    p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                            rs.getString("EP_NAME"), 
                            rs.getString("EP_DESCRIPTION"),
                            rs.getInt("EP_PRICE"),
                            rs.getInt("EP_STOCK"),
                            rs.getInt("EPC_ID"),
                            rs.getInt("EPC_CHILD_ID"),
                            rs.getString("EP_FILE_NAME"));
                    lastlylist.add(p);
                }
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }finally {
            Basedao.closeall(rs, ps, conn);
        }
        return lastlylist;
    }
    
    /**
     * 查询特价商品
     * @return
     */
    public static ArrayList selectAllByT(){
        ArrayList list = new ArrayList();
        Connection conn =Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from EASYBUY_PRODUCT order by EP_PRICE asc limit 0,9";
        try {
            ps = conn.prepareStatement(sql);
            
            rs = ps.executeQuery();
            while(rs.next()) {
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                        rs.getString("EP_NAME"), 
                        rs.getString("EP_DESCRIPTION"),
                        rs.getInt("EP_PRICE"),
                        rs.getInt("EP_STOCK"),
                        rs.getInt("EPC_ID"),
                        rs.getInt("EPC_CHILD_ID"),
                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        
        return list;
    }
    
    /**
     * 查询热卖商品
     * @return
     */
    public static ArrayList selectAllByHot(){
        ArrayList list = new ArrayList();
        Connection conn =Basedao.getconn();
        PreparedStatement ps = null;
        ResultSet rs = null;
        String sql = "select * from ( select tab1.* from  (  select * from easybuy_product a,  (select ep_id eod_ep_id,sum(EOD_QUANTITY) buysum from EASYBUY_ORDER_DETAIL  group by EP_id order by sum(EOD_QUANTITY) desc) b  where a.ep_id=b.eod_ep_id order by buysum desc  ) tab1) tab2 limit 0,8";
        try {
            ps = conn.prepareStatement(sql);
            
            rs = ps.executeQuery();
            while(rs.next()) {
                EASYBUY_PRODUCT p = new EASYBUY_PRODUCT(rs.getInt("EP_ID"),
                        rs.getString("EP_NAME"), 
                        rs.getString("EP_DESCRIPTION"),
                        rs.getInt("EP_PRICE"),
                        rs.getInt("EP_STOCK"),
                        rs.getInt("EPC_ID"),
                        rs.getInt("EPC_CHILD_ID"),
                        rs.getString("EP_FILE_NAME"));
                list.add(p);
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } finally {
            Basedao.closeall(rs, ps, conn);
        }
        
        return list;
    }
}

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>




猿来入此-商城 - 首页







<%@ include file="/include/search_bar.jsp" %>

    您现在的位置:猿来入此-商城 > 商品分类 > ${title }


    

        

            

商品分类


            

                
全部商品

                
                    
${f.EPC_NAME }

                    
                        
                            
                                
${c.EPC_NAME }

                            

                        

                    
 
                

            

        

        

        

            

最近浏览


            

                
                    

                    
${lastp.EP_NAME }

                

            

        

    

    

        

${p.EP_NAME }


        

        

            
            

        

        

             
            


                

商城价:¥${p.EP_PRICE }.00


                

邮递方式:圆通快递


                

热卖程度:☆☆☆☆☆


                

库 存:${p.EP_STOCK }


                

购买数量:


                
            

            

        

        

            

商品详情


            

                ${p.EP_DESCRIPTION }

            

        

    

    




你可能感兴趣的:(jsp+servlet+mysql实现的在线鲜花商城)