JAVAWeb采购管理系统

采购管理系统

正文

项目构思

简易的管理系统,结构为 Servlet + JSP + MySQL,使用,搭建起了这个项目,源码中有很详细的注释,如果刚开始学习JavaWeb的内容,学一下Servlet SSM ,再搭配这个项目,岂不是美滋滋,有需要就拿去,如果能够有帮助,在fork的同时也赏一个Star吧!

接下来就介绍一下过程:

1. 数据库连接

在这个项目中,并不是单独编写Java程序来连接数据库,而是使用c3p0-config.xml文件来配置数据库连接池,使用 QueryRunner 来执行数据库操作

在运行项目之前,需要在图中所示文件中设置你自己的本地数据库名称和密码,否则,无法连接数据库

运用技术:
SSM + redis + jsp + bootstrap(前台) + layui/bootstrap(后台) + jquery
实现功能:
首页:商品信息+视频播放+广告轮播
用户模块:个人信息+粉丝数量/关注数量
商品模块: 商品分类+商品详情+商品列表分页
资讯模块: 外链接
动态留言模块:发布动态+评论+图片发布
支付模块:微信支付+易宝支付

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

2. JAR文件

在构建项目时,需要导入所需的Library

JAVAWeb采购管理系统

3. 建表

在创建数据库时,也需要一张表来配合运行项目,在项目中也给出了这张表的结构

4. 建包

采用MVC设计模式,建包时我分成了这几个方面:

dao
page
product
service
servlet
以及在测试时的用例:demo

接下来介绍这几个包的内容:

  1. dao包:
    内含有一个Java文件:ProductDao,编写对于数据库的操作,增删改查之类

  2. page包:
    查询后的数据需要分页显示,否则看起来很麻烦,page包中包含有一个Java文件:PageBean,配合content.jsp文件将查询结果分页显示

  3. product包:
    内含有Product类,将商品的基本信息封装,便于其他类使用

  4. service包
    内含有一个Java文件:ProductService,实现了ProductDao类中定义的方法,并封装,降低程序中的代码重复性,更加简洁

  5. servlet包
    内含有ProductServlet,实现了ProductService类中定义的方法,并和JSP页面进行通信

  6. demo包
    在完成项目后,需要测试用例来进行测试

5. MVC模式

MVC模式:Model,View,Controller:

Model:ProductDao类,PageBean类和Product类作为基本的模型

View:JSP文件,系统的页面

Controller:ProductServlet,作为用户输入和数据库操作的控制者

这样就使得代码较为简洁

6. 运行前需要的准备

在Github上fork项目,并且clone至本地后,用IDEA打开,并按照这篇配置教程来配置web项目
【JavaWeb】IDEA如何创建及配置Web项目(多图)

配置后,将src目录下的 c3p0-config.xml 文件中的数据库信息改为自己的数据库信息,运行Tomcat,岂不是美滋滋

 

JAVAWeb采购管理系统

JAVAWeb采购管理系统

JAVAWeb采购管理系统

JAVAWeb采购管理系统

JAVAWeb采购管理系统

JAVAWeb采购管理系统

JAVAWeb采购管理系统

JAVAWeb采购管理系统

 

 

 

 

package com.oa.actions;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.oa.models.TOrder;
import com.oa.models.TProduct;
import com.oa.models.TSupplier;
import com.oa.services.OrderServices;
import com.oa.services.ProductServices;
import com.oa.services.SupplierServices;
import com.oa.utils.PageInfo;


public class OrderAction extends BaseAction{
    private OrderServices orderServices;
    private SupplierServices supplierServices;
    private ProductServices productServices;
    private Integer id;
    private Integer supplierid;
    private Integer productid;
    private String ordername;
    private String num;
    private String status;
    private String searchname;
    private String numb;
    private Float price;
    private Float allprice;
    private String username;
    private String remark; 


    
    public String queryOrder() throws Exception{
        if (getSessionAttribute("querypageunit") == null) {
            setSessionAttribute("querypageunit",this.pageunit);
        }
        StringBuffer cond = new StringBuffer();
        if(null!=searchname&&""!=searchname.trim()){
            cond.append(" and a.ordername like '%"+searchname.trim()+"%' ");
        }
        if(null!=getRequestParameter("flag") &&""!=getRequestParameter("flag")){
            setSessionAttribute("flag", getRequestParameter("flag"));
        }
        if(null!=getSessionAttribute("flag") &&""!=(String)getSessionAttribute("flag")){
            cond.append(" and a.status = '"+(String)getSessionAttribute("flag")+"' ");
        }
        
        int curpage = Integer.parseInt(this.getCurrentpage(ServletActionContext.getRequest()));
        int pageunit = Integer.parseInt(this.getPageunit(ServletActionContext.getRequest(), "querypageunit"));

        String url = "order_queryOrder?a=a";
        
        PageInfo pageInfo = this.orderServices.queryOrder(curpage,
                pageunit, ServletActionContext.getRequest(), url, cond.toString());
        setRequestAttribute("pageinfo", pageInfo);
        setRequestAttribute("searchname", this.searchname);
        return "queryOrder";
    }
    
    public String queryOrderUndo() throws Exception{
        if (getSessionAttribute("querypageunit") == null) {
            setSessionAttribute("querypageunit",this.pageunit);
        }
        StringBuffer cond = new StringBuffer();
        if(null!=searchname&&""!=searchname.trim()){
            cond.append(" and a.ordername like '%"+searchname.trim()+"%' ");
        }
        if(null!=getRequestParameter("flag") &&""!=getRequestParameter("flag")){
            setSessionAttribute("flag", getRequestParameter("flag"));
        }
        if(null!=getSessionAttribute("flag") &&""!=(String)getSessionAttribute("flag")){
            cond.append(" and a.status in ('0','1','2','3','4','6') ");
        }
        
        int curpage = Integer.parseInt(this.getCurrentpage(ServletActionContext.getRequest()));
        int pageunit = Integer.parseInt(this.getPageunit(ServletActionContext.getRequest(), "querypageunit"));

        String url = "order_queryOrderUndo?a=a";
        
        PageInfo pageInfo = this.orderServices.queryOrder(curpage,
                pageunit, ServletActionContext.getRequest(), url, cond.toString());
        setRequestAttribute("pageinfo", pageInfo);
        setRequestAttribute("searchname", this.searchname);
        return "queryOrder";
    }
    
    //为采购员获取订单数据
    public String purchaseOrder() throws Exception{
        PageInfo pageInfo0 =queryOrderByStatus("('0','3')");
        PageInfo pageInfo2 =queryOrderByStatus("('2')");
        setRequestAttribute("pageinfo0", pageInfo0);
        setRequestAttribute("pageinfo2", pageInfo2);
        setRequestAttribute("searchname", this.searchname);
        return "purchaseOrder";
    }
    
    
    public PageInfo queryOrderByStatus(String status){
        
        if (getSessionAttribute("querypageunit") == null) {
            setSessionAttribute("querypageunit",this.pageunit);
        }
        StringBuffer cond = new StringBuffer();
        if(null!=searchname&&""!=searchname.trim()){
            cond.append(" and a.ordername like '%"+searchname.trim()+"%' ");
        }
        if(null!=getRequestParameter("flag") &&""!=getRequestParameter("flag")){
            setSessionAttribute("flag", getRequestParameter("flag"));
        }
        if(null!=getSessionAttribute("flag") &&""!=(String)getSessionAttribute("flag")){
            //cond.append(" and a.status = '"+status+"' ");
            cond.append(" and a.status in "+status+" ");
        }
        
        int curpage = Integer.parseInt(this.getCurrentpage(ServletActionContext.getRequest()));
        int pageunit = Integer.parseInt(this.getPageunit(ServletActionContext.getRequest(), "querypageunit"));

        String url = "order_purchaseOrder?a=a";
        
        PageInfo pageInfo = this.orderServices.queryOrder(curpage,
                pageunit, ServletActionContext.getRequest(), url, cond.toString());
        return pageInfo;
        
    }
    
    //为审批员获取订单数据
    public String approveListOrder() throws Exception{
        PageInfo pageInfo0 =queryOrderByStatus("('1')");
        PageInfo pageInfo2 =queryOrderByStatus("('6')");
        setRequestAttribute("pageinfo0", pageInfo0);
        setRequestAttribute("pageinfo2", pageInfo2);
        setRequestAttribute("searchname", this.searchname);
        return "approveListOrder";
        }
    
        
        //为审批员获取订单数据
        public String storeListOrder() throws Exception{
            if (getSessionAttribute("querypageunit") == null) {
                setSessionAttribute("querypageunit",this.pageunit);
            }
            StringBuffer cond = new StringBuffer();
            if(null!=searchname&&""!=searchname.trim()){
                cond.append(" and a.ordername like '%"+searchname.trim()+"%' ");
            }
            if(null!=getRequestParameter("flag") &&""!=getRequestParameter("flag")){
                setSessionAttribute("flag", getRequestParameter("flag"));
            }
            if(null!=getSessionAttribute("flag") &&""!=(String)getSessionAttribute("flag")){
                cond.append(" and a.status = '"+(String)getSessionAttribute("flag")+"' ");
            }
            
            int curpage = Integer.parseInt(this.getCurrentpage(ServletActionContext.getRequest()));
            int pageunit = Integer.parseInt(this.getPageunit(ServletActionContext.getRequest(), "querypageunit"));

            String url = "order_storeListOrder?a=a";
            
            PageInfo pageInfo = this.orderServices.queryOrder(curpage,
                    pageunit, ServletActionContext.getRequest(), url, cond.toString());
            setRequestAttribute("pageinfo", pageInfo);
            setRequestAttribute("searchname", this.searchname);
            return "storeListOrder";
        }
    

    public String addOrder(){
        try {
            TOrder order = new TOrder();
            order.setNum(num);
            order.setOrdername(ordername);
            order.setStatus("0");
            TProduct product = productServices.getProduct(productid);
            order.setTProduct(product);
            TSupplier supplier = supplierServices.getSupplier(supplierid);
            order.setTSupplier(supplier);
            order.setNumb(numb);
            order.setPrice(price);
            order.setRemark(remark);
            order.setAllprice(allprice);
            order.setUsername(username);
            orderServices.addOrder(order);
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return "addOrder";
    }
    
    public String addOrderForPurchase(){
        try {
            TOrder order = new TOrder();
            order.setNum(num);
            order.setOrdername(ordername);
            order.setStatus("0");
            TProduct product = productServices.getProduct(productid);
            order.setTProduct(product);
            TSupplier supplier = supplierServices.getSupplier(supplierid);
            order.setTSupplier(supplier);
            order.setNumb(numb);
            order.setPrice(price);
            order.setRemark(remark);
            order.setAllprice(allprice);
            order.setUsername(username);
            orderServices.addOrder(order);
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return "addOrderForPurchase";
    }

    public String preaddOrder() throws Exception{
        List<TSupplier> list = supplierServices.querySupplier();
        setRequestAttribute("supplier",list);
        List<TProduct> list2 = productServices.queryProduct();
        setRequestAttribute("product",list2);
        return "preaddOrder";
    }
    
    public String preaddOrderForPurchase() throws Exception{
        List<TSupplier> list = supplierServices.querySupplier();
        setRequestAttribute("supplier",list);
        List<TProduct> list2 = productServices.queryProduct();
        setRequestAttribute("product",list2);
        return "preaddOrderForPurchase";
    }
    
    public String preupdateOrder() throws Exception{
        TOrder order = this.getOrderServices().getOrder(id);
        List<TSupplier> list = supplierServices.querySupplier();
        setRequestAttribute("supplier",list);
        List<TProduct> list2 = productServices.queryProduct();
        setRequestAttribute("product",list2);
        setRequestAttribute("order",order);
        return "preupdateOrder";
    }
    
    public String preupdateOrderForPurchase() throws Exception{
        TOrder order = this.getOrderServices().getOrder(id);
        List<TSupplier> list = supplierServices.querySupplier();
        setRequestAttribute("supplier",list);
        List<TProduct> list2 = productServices.queryProduct();
        setRequestAttribute("product",list2);
        setRequestAttribute("order",order);
        return "preupdateOrderForPurchase";
    }
    
    public String preapproveOrderForApproveList() throws Exception{
        TOrder order = this.getOrderServices().getOrder(id);
        List<TSupplier> list = supplierServices.querySupplier();
        setRequestAttribute("supplier",list);
        List<TProduct> list2 = productServices.queryProduct();
        setRequestAttribute("product",list2);
        setRequestAttribute("order",order);
        return "preapproveOrderForApproveList";
    }
    
    public String preapproveOrderReturnForApproveList() throws Exception{
        TOrder order = this.getOrderServices().getOrder(id);
        List<TSupplier> list = supplierServices.querySupplier();
        setRequestAttribute("supplier",list);
        List<TProduct> list2 = productServices.queryProduct();
        setRequestAttribute("product",list2);
        setRequestAttribute("order",order);
        return "preapproveOrderReturnForApproveList";
    }
    
    
    public String updateOrder() {
        try {
            TOrder order = this.getOrderServices().getOrder(id);
            order.setNum(num);
            order.setOrdername(ordername);
            TProduct product = productServices.getProduct(productid);
            order.setTProduct(product);
            TSupplier supplier = supplierServices.getSupplier(supplierid);
            order.setTSupplier(supplier);
            order.setNumb(numb);
            order.setPrice(price);
            order.setRemark(remark);
            order.setAllprice(allprice);
            order.setUsername(username);
            this.getOrderServices().updateOrder(order);
            
        } catch (RuntimeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "updateOrder";
    }
    
    public String updateOrderForPurchase() {
        try {
            TOrder order = this.getOrderServices().getOrder(id);
            order.setNum(num);
            order.setOrdername(ordername);
            TProduct product = productServices.getProduct(productid);
            order.setTProduct(product);
            TSupplier supplier = supplierServices.getSupplier(supplierid);
            order.setTSupplier(supplier);
            order.setNumb(numb);
            order.setPrice(price);
            order.setRemark(remark);
            order.setAllprice(allprice);
            order.setUsername(username);
            this.getOrderServices().updateOrder(order);
            
        } catch (RuntimeException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return "updateOrderForPurchase";
    }
    
    public String approveOrder() throws Exception{
        TOrder order = this.getOrderServices().getOrder(id);
        order.setStatus("1");
        this.getOrderServices().updateOrder(order);
        return "approveOrder";
    }
    
    //采购申请
    public String applyOrder() throws Exception{

        TOrder order = this.getOrderServices().getOrder(id);
        order.setStatus("1");
        this.getOrderServices().updateOrder(order);
        return "applyOrder";
    }
    
    //采购
    public String buyOrder() throws Exception{

        TOrder order = this.getOrderServices().getOrder(id);
        order.setStatus("4");
        this.getOrderServices().updateOrder(order);
        return "buyOrder";
    }
    
    //合格检查
    public String TestOrder() throws Exception{

        TOrder order = this.getOrderServices().getOrder(id);
        order.setStatus("5");
        this.getOrderServices().updateOrder(order);
        return "TestOrder";
    }
    
    //退货检查
        public String returnOrder() throws Exception{

            TOrder order = this.getOrderServices().getOrder(id);
            order.setStatus("6");
            this.getOrderServices().updateOrder(order);
            return "returnOrder";
        }
    
    //审批
    public String approveOrderForApproveList() throws Exception{

        TOrder order = this.getOrderServices().getOrder(id);
        order.setRemark(remark);
        order.setStatus(status);
        this.getOrderServices().updateOrder(order);
        return "approveOrderForApproveList";
    }
    
    public String approveOrderReturnForApproveList() throws Exception{

        TOrder order = this.getOrderServices().getOrder(id);
        order.setRemark(remark);
        order.setStatus(status);
        this.getOrderServices().updateOrder(order);
        return "approveOrderReturnForApproveList";
    }
    
    
    public String delOrder() throws Exception{
        orderServices.delOrder(id);
        return "delOrder";
    }
    
    public String delOrderForPurchase() throws Exception{
        orderServices.delOrder(id);
        return "delOrderForPurchase";
    }
    
    public OrderServices getOrderServices() {
        return orderServices;
    }
    public void setOrderServices(OrderServices orderServices) {
        this.orderServices = orderServices;
    }
    public SupplierServices getSupplierServices() {
        return supplierServices;
    }
    public void setSupplierServices(SupplierServices supplierServices) {
        this.supplierServices = supplierServices;
    }
    public ProductServices getProductServices() {
        return productServices;
    }
    public void setProductServices(ProductServices productServices) {
        this.productServices = productServices;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    public String getOrdername() {
        return ordername;
    }
    public void setOrdername(String ordername) {
        this.ordername = ordername;
    }
    public String getNum() {
        return num;
    }
    public void setNum(String num) {
        this.num = num;
    }
    public String getStatus() {
        return status;
    }
    public void setStatus(String status) {
        this.status = status;
    }
    public String getSearchname() {
        return searchname;
    }
    public void setSearchname(String searchname) {
        this.searchname = searchname;
    }
    public Integer getSupplierid() {
        return supplierid;
    }
    public void setSupplierid(Integer supplierid) {
        this.supplierid = supplierid;
    }
    public Integer getProductid() {
        return productid;
    }
    public void setProductid(Integer productid) {
        this.productid = productid;
    }
    public String getNumb() {
        return numb;
    }
    public void setNumb(String numb) {
        this.numb = numb;
    }
    public Float getPrice() {
        return price;
    }
    public void setPrice(Float price) {
        this.price = price;
    }
    public Float getAllprice() {
        return allprice;
    }
    public void setAllprice(Float allprice) {
        this.allprice = allprice;
    }
    public String getUsername() {
        return username;
    }
    public void setUsername(String username) {
        this.username = username;
    }
    public String getRemark() {
        return remark;
    }
    public void setRemark(String remark) {
        this.remark = remark;
    }
    
}
 

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>
<!-- 
功能介绍:系统登录界面

 -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>采购管理系统</title>
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function commit() {
    if(form1.username.value=="") {
        alert("请您输入用户名!");
        form1.username.focus();
        return false;
    }
    if(form1.password.value=="") {
        alert("请您输入密码!");
        form1.password.focus();
        return false;
    }
    return true;
}

</script>
</head>
<body>
<form action="login_checkUser" method="post" name="form1" οnsubmit="return commit()">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
<%-- <td height="147" background="images/top02.gif" width="100%" ><img src="images/top.png" width="100%" /></td> --%>
    
    <td height="147" width="100%" ></td>
  </tr>
</table>
<center style="background:#D7FFEE">
<fieldset style="width:562px;align=center">
<table width="562" border="0" align="center" cellpadding="0" cellspacing="0" class="right-table03">
<tr><td colspan="2" align="center">
<div style="font-family: 宋体;font-size: 30px;color: #7F9DB9;text-decoration: none;text-align:center;padding-top: 14px;">采购管理系统</div>
</td></tr>
  <tr>
    <td width="221"><table width="95%" border="0" cellpadding="0" cellspacing="0" class="login-text01">
      
      <tr>
        <td><table width="100%" border="0" cellpadding="0" cellspacing="0" class="login-text01">
          <tr>
            <td align="center"><div style="padding-top:50px"><img src="images/1ico13.gif" width="107" height="117" /></div></td>
          </tr>
          <tr>
            <td height="40" align="center">&nbsp;</td>
          </tr>
          
        </table></td>
        <td><img src="images/line01.gif" width="5" height="292" /></td>
      </tr>
    </table></td>
    <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="31%" height="35" class="login-text02">帐    号&nbsp;&nbsp;&nbsp;<br /></td>
        <td width="69%"><input name="username" id= "username" type="text" size="28" style="width:150px" /></td>
      </tr>
      <tr>
        <td height="35" class="login-text02">密    码&nbsp;&nbsp;&nbsp;<br /></td>
        <td><input name="password" id="password" type="password" size="30" style="width:150px"/></td>
      </tr>
      <tr>
        <td height="35">&nbsp;</td>
        <td><input name="Submit2" type="submit" class="right-button02" value="登 录" />
          &nbsp;&nbsp;<input name="reset232" type="reset"" class="right-button02" value="重 置" />
      </tr>      
      <%
      if("error".equals((String)request.getAttribute("error"))){ %>
          <font color="red">信息错误,请重新填写!</font>
      <%}%>
      
    </table></td>
  </tr>
</table>
</fieldset>
</center>
</form>
</body>
</html>