spring boot的一个小项目小型进销存系统

项目所需的依赖:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter</artifactId>
    </dependency>
        <!-- 核心依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
        <!-- 可以实现热部署,在IDEA上实现热部署还需一些额外的配置,请查阅资料 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-devtools</artifactId>
        <optional>true</optional>
        <scope>runtime</scope>
    </dependency>

        <!-- JDBC for mysql -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>


    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.32</version>
    </dependency>


    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

        <!-- mybatis -->
        <!--mybatis-->
        <!-- https://mvnrepository.com/artifact/org.mybatis.spring.boot/mybatis-spring-boot-starter -->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>1.3.1</version>
    </dependency>
        <!--fastJson-->

    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.12</version>
    </dependency>

        <!--druid-->



    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid</artifactId>
        <version>1.0.18</version>
    </dependency>
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
        <version>3.4.1</version>
    </dependency>

        <!--thymeleaf 新的模板引擎,比jsp要出色-->

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
        <!--jdbc-->
     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
     </dependency>

        <!-- 分页插件 -->
    <dependency>
        <groupId>com.github.pagehelper</groupId>
        <artifactId>pagehelper-spring-boot-starter</artifactId>
        <version>1.2.3</version>
    </dependency>



还需要在配置:resources
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.*</include>
</includes>
</resource>
</resources>
  

application.properties:

#开发配置

#数据源配置
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/invoicingsystem?useUnicode=true&characterEncoding=utf-8
spring.datasource.username=root
spring.datasource.password=123456

#Spring Data JPA配置
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jackson.serialization.indent-output=true
spring.jpa.database=mysql

spring.main.allow-bean-definition-overriding=true
server.port=8080



#spring.thymeleaf.prefix=classpath:/templates/

#配置mybatis
mybatis.configuration.auto-mapping-behavior=full
mybatis.type-aliases-package=com.invoicing.entity



#resources:
#static-locations: classpath:/resources/, classpath:/static/ ,classpath:/templates/
#spring.thymeleaf.prefix=classpath:/templates/

  

项目实体:

package com.invoicing.entity;

public class Product {
    private int pid;
    private String productName;
    private int quantity;

    public int getPid() {
        return pid;
    }

    public void setPid(int pid) {
        this.pid = pid;
    }

    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    public int getQuantity() {
        return quantity;
    }

    public void setQuantity(int quantity) {
        this.quantity = quantity;
    }
}



package com.invoicing.entity;


import java.math.BigDecimal;
import java.util.Date;


public class Sale {
private int sid;
private BigDecimal price;
private int quantity;
private BigDecimal totalPrice;
private Date saleDate;
private int userId;
private int productId;
private String remarks;
private Product product;
private Users users;

public int getSid() {
return sid;
}

public void setSid(int sid) {
this.sid = sid;
}

public BigDecimal getPrice() {
return price;
}

public void setPrice(BigDecimal price) {
this.price = price;
}

public int getQuantity() {
return quantity;
}

public void setQuantity(int quantity) {
this.quantity = quantity;
}

public BigDecimal getTotalPrice() {
return totalPrice;
}

public void setTotalPrice(BigDecimal totalPrice) {
this.totalPrice = totalPrice;
}

public Date getSaleDate() {
return saleDate;
}

public void setSaleDate(Date saleDate) {
this.saleDate = saleDate;
}

public int getUserId() {
return userId;
}

public void setUserId(int userId) {
this.userId = userId;
}

public int getProductId() {
return productId;
}

public void setProductId(int productId) {
this.productId = productId;
}

public String getRemarks() {
return remarks;
}

public void setRemarks(String remarks) {
this.remarks = remarks;
}

public Product getProduct() {
return product;
}

public void setProduct(Product product) {
this.product = product;
}

public Users getUsers() {
return users;
}

public void setUsers(Users users) {
this.users = users;
}
}



package com.invoicing.entity;



public class Users {
private int uid;
private String userName;
private String password;
private String realName;

public int getUid() {
return uid;
}

public void setUid(int uid) {
this.uid = uid;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getRealName() {
return realName;
}

public void setRealName(String realName) {
this.realName = realName;
}
}

项目的Dao层:

IProductDao层 :
package com.invoicing.dao;

import com.invoicing.entity.Product;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("iProductDao")
public interface IProductDao {

    //获取所有库存中的商品
    List<Product> getProductList();

    //根据id获得对应的ID
    Product getProduct(Integer id);

    //修改库存的数量
    Integer  updateProduct(@Param("quantity") Integer quantity,@Param("id") Integer id);
}




实现dao层的方法:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.invoicing.dao.IProductDao">
<!-- 目的:为dao接口方法提供sql语句配置 -->
<select id="getProductList" resultType="Product" >
<!-- 具体的sql -->
select * from product
</select>


<!-- 目的:为dao接口方法提供sql语句配置 -->
<select id="getProduct" resultType="Product" >
<!-- 具体的sql -->
select * from product where pid=#{id}
</select>


<!-- 目的:为dao接口方法提供sql语句配置 -->
<update id="updateProduct">
<!-- 具体的sql -->
update product set quantity=quantity-#{quantity} where pid=#{id}
</update>
</mapper>

  

  

ISalesDao 层:
package com.invoicing.dao;


import com.invoicing.entity.Sale;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("iSalesDao")
public interface ISalesDao {

    //添加销售记录
    Integer addSale(Sale sale);


    /**
     *   根据传过来的参数
     *   (if oder==1 那么获取的所有销售记录根据日期排序,
     *   if id==2 获取的所有销售记录销售的总数排序)
     *   获取所有的销售记录
     */
    List<Sale> getListSale(@Param("order") String order);

}


实现dao层的方法:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.invoicing.dao.ISalesDao">
<!-- 目的:为dao接口方法提供sql语句配置 -->
<resultMap id="salelist" type="Sale">
<id column="sid" property="sid"/>
<result column="price" property="price"/>
<result column="quantity" property="quantity"/>
<result column="totalPrice" property="totalPrice"/>
<result column="saleDate" property="saleDate"/>
<association property="product" javaType="Product" column="productId">
<id column="pid" property="pid"/>
<result column="productName" property="productName"/>
<result column="quantity" property="quantity"/>
</association>
<association property="users" javaType="Users" column="userId">
<id column="uid" property="uid"/>
<result column="userName" property="userName"/>
<result column="password" property="password"/>
<result column="realName" property="realName"/>
</association>
</resultMap>
<insert id="addSale" >
<!-- 具体的sql -->
INSERT INTO sale (price,quantity,totalPrice,saleDate,userId,productId,remarks)
VALUES (#{price},#{quantity},#{totalPrice},#{saleDate},#{userId},#{productId},#{remarks})
</insert>

<select id="getListSale" resultMap="salelist">
select product.pid,product.productName,users.*,sale.* from product,users,sale where sale.userId=users.uid and sale.productId=product.pid
<if test="order==0">
order by sale.saleDate desc
</if>
<if test="order ==1">
order by sale.totalPrice desc
</if>
</select>


</mapper>

  

IUserDao 层:
package com.invoicing.dao;


import com.invoicing.entity.Users;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

@Repository("iUserDao")
public interface IUserDao {
    //登录
    Users login(@Param("username") String username);
}


实现dao层的方法:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.invoicing.dao.IUserDao">
<!-- 目的:为dao接口方法提供sql语句配置 -->
<select id="login" resultType="Users" >
<!-- 具体的sql -->
select * from users where userName=#{username}
</select>


</mapper>

 

service层: 

IProductService :
package com.invoicing.service;


import com.invoicing.entity.Product;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface IProductService {


    //获取所有库存中的商品
    List<Product> getProductList();

    //根据id获得对应的ID
    Product getProduct(Integer id);

    //修改库存的数量
    Integer  updateProduct( Integer quantity,  Integer id);
}



service层的impl实现:
package com.invoicing.service.impl;


import com.invoicing.dao.IProductDao;
import com.invoicing.entity.Product;
import com.invoicing.service.IProductService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("iProductService")
public class IProductServiceImpl implements IProductService {

@Resource(name = "iProductDao")
private IProductDao iProductDao;
@Override
public List<Product> getProductList() {
return iProductDao.getProductList();
}

@Override
public Product getProduct(Integer id) {
return iProductDao.getProduct(id);
}

@Override
public Integer updateProduct(Integer quantity, Integer id) {
return iProductDao.updateProduct(quantity,id);
}
}

  

ISalesSerivce :
package com.invoicing.service;

import com.github.pagehelper.PageInfo;
import com.invoicing.entity.Sale;


public interface ISalesSerivce {

    //添加销售记录
    Integer addSale(Sale sale);


    /**
     *   根据传过来的参数
     *   (if oder==1 那么获取的所有销售记录根据日期排序,
     *   if id==2 获取的所有销售记录销售的总数排序)
     *   获取所有的销售记录
     */
    PageInfo<Sale> getListSale(String order, int pageNum, int pageSize);
}


service层的impl实现:
package com.invoicing.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.invoicing.dao.ISalesDao;
import com.invoicing.entity.Sale;
import com.invoicing.service.ISalesSerivce;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;

@Service("iSalesSerivce")
public class ISalesSerivceImpl implements ISalesSerivce {

@Resource(name = "iSalesDao")
private ISalesDao iSalesDao;

@Override
public Integer addSale(Sale sale) {
return iSalesDao.addSale(sale);
}

@Override
public PageInfo<Sale> getListSale(String order, int pageNum, int pageSize) {
Page<Sale> page = PageHelper.startPage(pageNum, pageSize); //进行PageHelper分页
List<Sale> listSale = iSalesDao.getListSale(order);
return page.toPageInfo();
}
}

  

IUserService :
package com.invoicing.service;


import com.invoicing.entity.Users;

public interface IUserService {

    //登录
    Users login(String username, String password);
}

service层的impl实现:
package com.invoicing.service.impl;


import com.invoicing.dao.IUserDao;
import com.invoicing.entity.Users;
import com.invoicing.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("iUserService")
public class IUserServiceImpl implements IUserService {

@Resource(name = "iUserDao")
private IUserDao iUserDao;


@Override
public Users login(String username, String password) {
Users login =iUserDao.login(username);
if (login!=null && login.getPassword().equals(password) ){
return login;
}
return null;
}
}

  

Controller层:
IProductController :
 
package com.invoicing.controller;


import com.invoicing.entity.Product;
import com.invoicing.service.IProductService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@Controller
public class IProductController {
    @Resource(name = "iProductService")
    private IProductService iProductService;

    //获取所有库存表的信息
    @RequestMapping(value = "/getProductList", method = RequestMethod.POST)
    @ResponseBody
    private Object getProductList(HttpServletRequest request, HttpServletResponse response) throws IOException {
        List<Product> productList = iProductService.getProductList();
        return productList;
    }
}

  

ISalesController :
package com.invoicing.controller;


import com.github.pagehelper.PageInfo;
import com.invoicing.entity.Product;
import com.invoicing.entity.Sale;
import com.invoicing.entity.Users;
import com.invoicing.service.IProductService;
import com.invoicing.service.ISalesSerivce;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.math.BigDecimal;
import java.util.Date;


@Controller
public class ISalesController {

    @Resource(name = "iSalesSerivce")
    private ISalesSerivce iSalesSerivce;

    @Resource(name = "iProductService")
    private IProductService iProductService;


    @RequestMapping(value = "/addSale", method = RequestMethod.POST)
    private String addSale(@RequestParam String product, String price, String quantity, String remarks, HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("addSale"+":///"+product+"///"+price+"///"+quantity+"///"+remarks);
        double totalPrice =Double.valueOf(price)*Double.valueOf(quantity);
        Sale sale = new Sale();
        sale.setPrice(BigDecimal.valueOf(Integer.valueOf(price)));
        sale.setProductId(Integer.valueOf(product));
        sale.setQuantity(Integer.valueOf(quantity));
        sale.setTotalPrice(BigDecimal.valueOf(totalPrice));
        Users users=(Users)request.getSession().getAttribute("user");
        sale.setUserId(users.getUid());
        sale.setSaleDate(new Date());
        sale.setRemarks(remarks);
        //根据id获取对象
        Product pquantity = iProductService.getProduct(Integer.valueOf(product));

        //根据获取的对象和传过来的对象进行判断如果小于那么返回添加失败
        if (pquantity.getQuantity()>=Integer.valueOf(quantity)){
            Integer integer1 = iProductService.updateProduct(Integer.valueOf(quantity), Integer.valueOf(product));
            //判断Product中的数据修改成功吗,如果失败更换添加失败
            if (integer1>0){
                Integer integer = iSalesSerivce.addSale(sale);
                request.getSession().setAttribute("ByVal","sales");
                //判断向Sale表中添加数据成功,成功返回云
                if(integer>0){
                    response.setContentType("text/html; charset=UTF-8"); //转码
                    PrintWriter out = response.getWriter();
                    out.flush();
                    out.println("<script>");
                    out.println("alert('添加成功');");
                    out.println("</script>");
                }else{
                    response.setContentType("text/html; charset=UTF-8"); //转码
                    PrintWriter out = response.getWriter();
                    out.flush();
                    out.println("<script>");
                    out.println("alert('添加失败');");
                    out.println("</script>");
                }
            }else {
                response.setContentType("text/html; charset=UTF-8"); //转码
                PrintWriter out = response.getWriter();
                out.flush();
                out.println("<script>");
                out.println("alert('添加失败');");
                out.println("</script>");
            }
        }else {
            response.setContentType("text/html; charset=UTF-8"); //转码
            PrintWriter out = response.getWriter();
            out.flush();
            out.println("<script>");
            out.println("alert('添加失败,你输入的数量大于库存数量');");
            out.println("</script>");
        }

        return "index";
    }


    //获取所有销售数据进行分页并进行绑定
    @RequestMapping(value = "/getListSale", method = RequestMethod.POST)
    @ResponseBody
    private Object getListSale(String order, int pageNum, HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("   getListSale"+":///"+order);
        int pageSize=5;
        PageInfo<Sale> listSale = iSalesSerivce.getListSale(order,pageNum+1,pageSize);
        for (Sale s: listSale.getList()
             ) {
            System.out.println(s.getSid());
        }
        return listSale;
    }
}

  

IUserController :
package com.invoicing.controller;


import com.invoicing.entity.Users;
import com.invoicing.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;


@Controller
public class IUserController {
    @Resource(name = "iUserService")
    private IUserService iUserService;


    //跳转到登录页面
    @RequestMapping("/getLogin")
    private String getLogin() {
        return "login";
    }

    //登录
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    private String login(String username, String password, HttpServletRequest request, HttpServletResponse response) throws IOException {
        System.out.println("测试:"+username+"//////"+password);
        Users user = iUserService.login(username,password);
        if (user!=null){
            request.getSession().setAttribute("ByVal","index");
            request.getSession().setAttribute("user",user);
            return "index";
        }else {
            response.setContentType("text/html; charset=UTF-8"); //转码
            PrintWriter out = response.getWriter();
            out.flush();
            out.println("<script>");
            out.println("alert('用户名或者密码错误!');");
            out.println("</script>");
        }
        return "login";
    }

    //退出
    @RequestMapping(value = "/out", method = RequestMethod.GET)
    private String out(HttpServletRequest request, HttpServletResponse response) {
        request.getSession().removeAttribute("user");
        return "login";
    }


    //跳转到主页
    @RequestMapping(value = "/judgePage", method = RequestMethod.POST)
    @ResponseBody
    private Object judgePage(HttpServletRequest request, HttpServletResponse response) {
        String byVal = request.getSession().getAttribute("ByVal").toString();
        if(byVal==null){
            byVal="index";
        }
        return byVal;
    }




}

  

页面:

index.html:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="css/pagination.css"/>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript" src="js/jquery.pagination.js"></script>
    <script>
        $(function () {
            //判断添加成功后,是添加页码
            $.ajax({
                type:"POST",
                url:"/judgePage",
                dataType:"text",
                success: function(data){
                   if (data=="sales"){
                       $("#index").hide();
                       $("#Products").hide();
                       $("#select").hide();
                       $("#sales").show();
                   }else {
                       $("#sales").hide();
                       $("#Products").hide();
                       $("#select").hide();
                   }
                }
            });
        })

        //跳转到添加销售信息的页面
        function sales() {
            $("#index").hide();
            $("#Products").hide();
            $("#select").hide();
            $("#sales").show();
            $("#p").remove();
            //添加销售信息的页面的下拉框信息绑定
            bindsales();
        }
        function bindsales() {
            //添加销售信息的页面的下拉框信息绑定
            $.ajax({
                type:"POST",
                url:"/getProductList",
                dataType:"JSON",
                success: function(data){
                    $("#product option:not(option:first)").remove();
                    $.each(data,function (i,dom) {
                       $("#product").append("<option value='"+dom.pid+"'>"+dom.productName+"</option>");

                    })

                }
            });
        }
        //跳转到展示销售信息的页面
        function products() {
            $("#index").hide();
            $("#sales").hide();
            $("#select").hide();
            $("#Products").show();
            $("#p").remove();
            load(0);
        }
        //补0操作
        function getzf(num){
            if(parseInt(num) < 10){
                num = '0'+num;
            }
            return num;
        }
        //str为传入的字符串为毫秒值
        function getMyDate(str){
            var oDate = new Date(str),
                oYear = oDate.getFullYear(),
                oMonth = oDate.getMonth()+1,
                oDay = oDate.getDate(),
                oHour = oDate.getHours(),
                oMin = oDate.getMinutes(),
                oSen = oDate.getSeconds(),
                oTime = oYear +'-'+ getzf(oMonth) +'-'+ getzf(oDay) ;
            //最后拼接时间为 1999-10-02 样式
            return oTime;
        };

        //跳转到展示销售信息的的绑定
        function load(pageNum) {
            var order=$("[name=order]").val();
            $.ajax({
                type:"POST",
                url:"/getListSale",
                data:{"order":order,"pageNum":pageNum},
                dataType:"JSON",
                success: function(pageInfo){
                    $("#prod tr:not(tr:first)").remove();
                    $.each(pageInfo.list,function (i,dom) {
                        $("#prod").append("<tr> " +
                            "<td>"+dom.sid+"</td>" +
                            "<td>"+dom.product.productName+"</td> " +
                            "<td>"+dom.price+"</td> " +
                            "<td>"+dom.quantity+"</td> " +
                            "<td>"+dom.totalPrice+"</td>" +
                            "<td>"+getMyDate(dom.saleDate)+"</td> " +
                            "<td>"+dom.users.userName+" </td> " +
                            "</tr></tr> ");
                    })
                    $('#pagination').pagination(pageInfo.total, {
                        current_page : pageNum,
                        items_per_page : pageInfo.pageSize,
                        callback:load,
                        load_first_page : true,
                        prev_text : '上一页',
                        next_text : '下一页'
                    })
                }
            });

        }

        //跳转到查看库存的页面
        function select() {
            $("#index").hide();
            $("#Products").hide();
            $("#select").show();
            $("#sales").hide();
            $("#p").remove();
            bindselect()
        }

        //查看库存的页面的下拉框绑定
        function bindselect() {
            $.ajax({
                type:"POST",
                url:"/getProductList",
                dataType:"JSON",
                success: function(data){
                    $("#selectshop option:not(option:first)").remove();
                    $.each(data,function (i,dom) {
                        $("#selectshop").append("<option value='"+dom.pid+"'>"+dom.productName+"</option>");
                    })

                }
            });
        }


        //根据选择的信息来显示框架
        function sumbit() {
            var order=$("[name=shop]").val();
            $.ajax({
                type:"POST",
                url:"/getProductList",
                dataType:"JSON",
                success: function(data){
                    $("#p").remove();
                    $.each(data,function (i,dom) {
                        if (order==dom.pid) {
                            $("#out").append("<h2 id='p'>该商品的库存数量是:"+dom.quantity+"</h2>")
                        }
                    })

                }
            });
        }
    </script>
</head>
<body>
<div align="center">
    <div>
        <table>
            <tr>
                <td> 欢迎:<span th:text="${session.user.userName}"></span>,<a href="/out">退出登录</a></td>
            </tr>
            <tr>
                <td width="50px">
                    <a href="javaScript:;"  onclick="sales()" >销售</a><br><br>
                    <a href="javaScript:;"  onclick="products()">销售信息查询</a><br><br>
                    <a href="javaScript:;"  onclick="select()">查看库存</a><br><br>
                </td>
                <td rowspan="2" >
                    <div style="border: #0c89de 1px solid ; 600px;height: 300px">
                        <div id="index">
                            <br><br><br><br><br>
                            <h1 align="center">欢迎使用小型进销存系统</h1>
                        </div>
                        <div id="sales" align="center">
                            <h2 >添加销售</h2>
                            <form action="/addSale" method="post" >
                                商品名称:<select style="180px;height: 25px" id="product" name="product">
                                <option >--请选择商品--</option>
                            </select><br/><br/>
                                销售单价:<input style="180px;height: 25px" type="text" name="price"><br/><br/>
                                销售数量:<input style="180px;height: 25px" type="text" name="quantity"><br/><br/>
                                备注:      <input style="180px;height: 25px" type="text" name="remarks"><br/><br/>
                                <input type="submit" value="提交">
                            </form>
                        </div>
                        <div id="Products" align="center">
                            <br><br><br>
                            <span style="font-weight: bolder">销售信息查询:</span>
                                         
                            排序方式:<select name="order">
                            <option value="0">销售日期</option>
                            <option value="1">单笔总价</option>
                        </select>
                            <button  onclick="load(0)">提交</button>
                            <table border="2px" id="prod">
                                <tr>
                                    <th>ID</th>
                                    <th>商品</th>
                                    <th>单价</th>
                                    <th>数量</th>
                                    <th>总价</th>
                                    <th>销售日期</th>
                                    <th>销售员</th>
                                </tr>
                            </table>
                            <div class="pagination" id="pagination" align="center"></div>

                        </div>
                        <div id="select" align="center">
                            <br><br><br>
                            <span style="font-weight: bolder">销售信息查询:</span>
                                         
                            排序方式:<select name="shop"  id="selectshop">
                            <option value="0">--请选择商品--</option>
                        </select>
                            <button onclick="sumbit()" >提交</button>
                            <div id="out">

                            </div>
                        </div>
                    </div>
                </td>
            </tr>
        </table>
    </div>
    <div>

    </div>

</div>
</body>
</html>

  login.html


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
</head>
<body>
<div align="center">
    <br/>
    <div align="center" style="background-color:greenyellow ; 600px;height: 250px">
        <br/>
        <div >
            <h1>小型进销存系统</h1>
            <form METHOD="post" ACTION="/login">
                用户名:<input type="text" name="username"><br/><br/>
                密码:      <input type="password" name="password"><br/><br/>
                <input type="submit" value="登录">
            </form>
        </div>
    </div>
</div>
</body>
</html>
原文地址:https://www.cnblogs.com/wishsaber/p/11996542.html