基于javaweb+jsp的二手物品交易管理系统
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架…均可
开发工具:idea或eclipse或myeclipse
部分代码实现JSP
} }) }) function searchList() { window.location.href = "JiaoyiServlet?action=list&searchColumn="+document.getElementById("searchColumn").value+"&keyword=" + document.getElementById("search_keyword").value; } //增加表单提交之前进行检查,如果return false,则不允许提交 function addCheck() { //根据ID获取值 if (document.getElementById("add-jiaoyiName").value.trim().length == 0) { alert("物品名不能为空"); return false; } if (document.getElementById("add-jiaoyiSale").value.trim().length == 0) { alert("卖家不能为空"); return false; } if (document.getElementById("add-jiaoyiPhone").value.trim().length == 0) { alert("卖家手机不能为空"); return false; }
//编辑表单提交之前进行检查,如果return false,则不允许提交 function editCheck() { //根据ID获取值 if (document.getElementById("edit-jiaoyiName").value.trim().length == 0) { alert("物品名不能为空"); return false; } if (document.getElementById("edit-jiaoyiSale").value.trim().length == 0) { alert("卖家不能为空"); return false; } if (document.getElementById("edit-jiaoyiPhone").value.trim().length == 0) { alert("卖家手机不能为空"); return false; } if (document.getElementById("edit-jiaoyiBuy").value.trim().length == 0) { alert("买家不能为空"); return false;
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> <%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>交易管理</title> <link rel="stylesheet" href="css/bootstrap.css"> <link rel="stylesheet" href="css/main.css"> <script src="js/jquery-3.5.1.js"></script>
<div class="modal fade" id="modal-add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <form action="JiaoyiServlet" onsubmit="return addCheck()"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h4 class="modal-title" id="myModalLabel">增加交易</h4> </div> <div class="modal-body"> <div class="form-group hidden"> <label class="control-label">(hidden)</label> <input type="text" class="form-control" name="action" value="add"> </div> <div class="form-group"> <label for="add-jiaoyiName" class="control-label">物品名:</label> <input type="text" class="form-control" name="jiaoyiName" id="add-jiaoyiName"> </div>
<label for="add-jiaoyiSale" class="control-label">卖家:</label> <input type="text" class="form-control" name="jiaoyiSale" id="add-jiaoyiSale"> </div> <div class="form-group"> <label for="add-jiaoyiPhone" class="control-label">卖家手机:</label> <input type="text" class="form-control" name="jiaoyiPhone" id="add-jiaoyiPhone"> </div> <div class="form-group"> <label for="add-jiaoyiBuy" class="control-label">买家:</label> <input type="text" class="form-control" name="jiaoyiBuy" id="add-jiaoyiBuy"> </div> <div class="form-group"> <label for="add-jiaoyiBuyphone" class="control-label">买家手机:</label> <input type="text" class="form-control" name="jiaoyiBuyphone" id="add-jiaoyiBuyphone"> </div> <div class="form-group"> <label for="add-jiaoyiDate" class="control-label">交易时间:</label>
</form> </div> </div> </div> <!-- edit --> <div class="modal fade" id="modal-edit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <form action="JiaoyiServlet" onsubmit="return editCheck()"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h4 class="modal-title">更新交易</h4> </div> <div class="modal-body"> <div class="form-group hidden"> <label class="control-label">(hidden)</label>
aria-labelledby="myModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <form> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h4 class="modal-title">交易</h4> </div> <div class="modal-body"> <table class="table table-striped table-hover" style="font-size: 15px;"> <tr> <td style="width: 15%;">物品名:</td>
alert("买家不能为空"); return false; } if (document.getElementById("add-jiaoyiBuyphone").value.trim().length == 0) { alert("买家手机不能为空"); return false; } if (document.getElementById("add-jiaoyiDate").value.trim().length == 0) { alert("交易时间不能为空"); return false; } if (document.getElementById("add-jiaoyiAddress").value.trim().length == 0) { alert("交易地点不能为空"); return false; } return true;
</head> <body> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container-fluid"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">二手物品交易管理系统</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">二手物品交易管理系统</a> </div> <div id="navbar" class="navbar-collapse collapse"> <ul class="nav navbar-nav navbar-right"> <li><a href="#">欢迎:<span style="color: yellow">${loginUser.username}</span></a></li>
</ul> </div> </div> </nav> <div class="container-fluid"> <div class="row"> <div class="col-sm-3 col-md-2 sidebar"> <!-- 侧边栏 --> <jsp:include page="menu.jsp"> <jsp:param value="active" name="Jiaoyi_active"/> </jsp:include> </div>
</form> </div> </div> </div> </body> <script> $('#modal-delete').on('show.bs.modal', function (event) { let button = $(event.relatedTarget); let id = button.data('id'); let modal = $(this); modal.find('#delete-id').val(id); }) $('#modal-edit').on('show.bs.modal', function (event) {
<td style="width: 15%;">交易时间:</td> <td><b id="info-jiaoyiDate"></b></td> </tr> <tr> <td style="width: 15%;">交易地点:</td> <td><b id="info-jiaoyiAddress"></b></td> </tr> <tr> <td style="width: 15%;">备注:</td> <td><b id="info-jiaoyiText"></b></td> </tr> </table> <br> </div> <div class="modal-footer"> <button type="button" class="btn btn-rect btn-grad btn-success" data-dismiss="modal">关闭</button>
<input type="text" readonly class="form-control" name="id" id="edit-id"> </div> <div class="form-group"> <label for="edit-jiaoyiName" class="control-label">物品名:</label> <input type="text" class="form-control" name="jiaoyiName" id="edit-jiaoyiName"> </div> <div class="form-group"> <label for="edit-jiaoyiSale" class="control-label">卖家:</label> <input type="text" class="form-control" name="jiaoyiSale" id="edit-jiaoyiSale"> </div> <div class="form-group"> <label for="edit-jiaoyiPhone" class="control-label">卖家手机:</label> <input type="text" class="form-control" name="jiaoyiPhone" id="edit-jiaoyiPhone"> </div> <div class="form-group"> <label for="edit-jiaoyiBuy" class="control-label">买家:</label>
<div class="modal-dialog" role="document"> <div class="modal-content"> <form action="JiaoyiServlet"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"> <span aria-hidden="true">×</span> </button> <h4 class="modal-title">删除交易</h4> </div> <div class="modal-body"> 确认要删除该交易记录吗? <div class="form-group hidden"> <label class="control-label">(hidden)</label> <input type="hidden" class="form-control" name="action" value="delete"> <input type="text" class="form-control" name="id" id="delete-id"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-rect btn-grad btn-success" data-dismiss="modal">取消</button> <button type="submit" class="btn btn-rect btn-grad btn-primary">删除</button>
</button> <button class="btn btn-rect btn-grad btn-primary btn-sm" <c:if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限!!!"</c:if> data-id="${vo.id}" data-toggle="modal" data-target="#modal-delete">删除 </button> </th> </tr> </c:forEach> </tbody> </table> </div> <div style="float: right;padding-right: 10px;color: #515151;"><jsp:include page="split.jsp"/></div> </div> </div> </div>
</div> <div class="form-group"> <label for="add-jiaoyiAddress" class="control-label">交易地点:</label> <input type="text" class="form-control" name="jiaoyiAddress" id="add-jiaoyiAddress"> </div> <div class="form-group"> <label for="add-jiaoyiText" class="control-label">备注:</label> <textarea style="height: 100px;" class="form-control" name="jiaoyiText" id="add-jiaoyiText"></textarea> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-rect btn-grad btn-success" data-dismiss="modal">取消</button> <button type="submit" class="btn btn-rect btn-grad btn-danger">提交</button> </div> </form> </div> </div> </div> <!-- info -->
<td>${vo.jiaoyiPhone}</td> <td>${vo.jiaoyiBuy}</td> <td>${vo.jiaoyiBuyphone}</td> <td>${vo.jiaoyiDate}</td> <td>${vo.jiaoyiAddress}</td> <th style="text-align: center;"> <button class="btn btn-rect btn-grad btn-info btn-sm" data-id="${vo.id}" data-toggle="modal" data-target="#modal-info">详情 </button> <button class="btn btn-rect btn-grad btn-primary btn-sm" <c:if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限!!!"</c:if> data-id="${vo.id}"
</tr> <tr> <td style="width: 15%;">卖家:</td> <td><b id="info-jiaoyiSale"></b></td> </tr> <tr> <td style="width: 15%;">卖家手机:</td> <td><b id="info-jiaoyiPhone"></b></td> </tr> <tr> <td style="width: 15%;">买家:</td> <td><b id="info-jiaoyiBuy"></b></td> </tr> <tr> <td style="width: 15%;">买家手机:</td> <td><b id="info-jiaoyiBuyphone"></b></td> </tr>
</div> <div class="form-group"> <label for="edit-jiaoyiBuyphone" class="control-label">买家手机:</label> <input type="text" class="form-control" name="jiaoyiBuyphone" id="edit-jiaoyiBuyphone"> </div> <div class="form-group"> <label for="edit-jiaoyiDate" class="control-label">交易时间:</label> <input type="text" class="form-control" name="jiaoyiDate" id="edit-jiaoyiDate"> </div> <div class="form-group"> <label for="edit-jiaoyiAddress" class="control-label">交易地点:</label> <input type="text" class="form-control" name="jiaoyiAddress" id="edit-jiaoyiAddress">
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main"> <div class="row"> <div class="col-sm-7"> <div class="input-group"> <input class="form-control" type="hidden" id="searchColumn" name="searchColumn" value="jiaoyi_name"/> <input class="form-control" type="text" id="search_keyword" name="search_keyword" placeholder="物品名"/> <span class="input-group-btn"><button class="btn btn-rect btn-grad btn-primary" type="button" onclick="searchList()">搜索</button></span> </div> </div> <div class="col-sm-5"> <button type="button" <c:if test="${loginUser.userType != '管理员'}">disabled="disabled" title="没有权限!!!"</c:if> class="btn btn-rect btn-grad btn-danger" data-toggle="modal" data-target="#modal-add">添加交易 </button> </div> </div> <br> <br> <div class="table-responsive">
modal.find('#edit-jiaoyiAddress').val(vo.jiaoyiAddress); modal.find('#edit-jiaoyiText').val(vo.jiaoyiText); } }) }) $('#modal-info').on('show.bs.modal', function (event) { let button = $(event.relatedTarget); let id = button.data('id'); let modal = $(this); $.ajax({ url: 'JiaoyiServlet?action=get&id=' + id, type: "get", success: function (voString) { let vo = eval('(' + voString + ')'); modal.find('#info-jiaoyiName').text(vo.jiaoyiName); modal.find('#info-jiaoyiSale').text(vo.jiaoyiSale); modal.find('#info-jiaoyiPhone').text(vo.jiaoyiPhone); modal.find('#info-jiaoyiBuy').text(vo.jiaoyiBuy); modal.find('#info-jiaoyiBuyphone').text(vo.jiaoyiBuyphone); modal.find('#info-jiaoyiDate').text(vo.jiaoyiDate); modal.find('#info-jiaoyiAddress').text(vo.jiaoyiAddress);
<div class="form-group"> <label for="edit-jiaoyiText" class="control-label">备注:</label> <textarea style="height: 100px;" class="form-control" name="jiaoyiText" id="edit-jiaoyiText"></textarea> </div> <div class="form-group hidden"> <label for="edit-createTime" class="control-label">创建时间:</label> <input type="text" class="form-control" name="createTime" id="edit-createTime"> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-rect btn-grad btn-success" data-dismiss="modal">取消</button> <button type="submit" class="btn btn-rect btn-grad btn-danger">提交</button> </div> </form> </div> </div> </div> <!-- delete -->
<thead> <tr> <th>物品名</th> <th>卖家</th> <th>卖家手机</th> <th>买家</th> <th>买家手机</th> <th>交易时间</th> <th>交易地点</th> <th style="text-align: center;">操作</th> </tr> </thead> <tbody> <c:forEach items="${list}" var="vo"> <tr> <td>${vo.jiaoyiName}</td>
let id = button.data('id'); let modal = $(this); $.ajax({ url: 'JiaoyiServlet?action=get&id=' + id, type: "get", success: function (voString) { let vo = eval('(' + voString + ')'); modal.find('#edit-id').val(vo.id); modal.find('#edit-jiaoyiName').val(vo.jiaoyiName); modal.find('#edit-jiaoyiSale').val(vo.jiaoyiSale); modal.find('#edit-jiaoyiPhone').val(vo.jiaoyiPhone); modal.find('#edit-jiaoyiBuy').val(vo.jiaoyiBuy); modal.find('#edit-jiaoyiBuyphone').val(vo.jiaoyiBuyphone);
if (document.getElementById("edit-jiaoyiBuyphone").value.trim().length == 0) { alert("买家手机不能为空"); return false; } if (document.getElementById("edit-jiaoyiDate").value.trim().length == 0) { alert("交易时间不能为空"); return false; } if (document.getElementById("edit-jiaoyiAddress").value.trim().length == 0) { alert("交易地点不能为空"); return false; } return true; } </script>
Java代码:略
运行环境
Java≥6、Tomcat≥7.0、MySQL≥5.5
开发工具
idea/eclipse/MyEclipse
技术框架
JavaWeb JavaBean JSP MVC MySQL Tomcat JavaScript
基础JSP+Servlet或JSP+SSM(Spring、SpringMVC、MyBatis)框架或JSP+SSM+Maven(pom.xml)框架…均可
开发工具:idea或eclipse或myeclipse
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
登录、注册、退出、用户模块、公告模块、物品模块、交易模块的增删改查管理