content
Java+JSP system series implementation
Java+Servlet system series implementation
Java+SSM system series implementation
Java+SSH system series implementation
Java+Springboot system series implementation
1. System introduction
1. Development environment
Development tool: IDEA2018
JDK version: Jdk1.8
Mysql version: 8.0.13
2. Technical selection
Java+Jsp+Mysql
3. System function
1. Log in to the system;
2. The administrator's addition, deletion, modification and inspection of product information.
4. Database file
/*
Navicat Premium Data Transfer
Source Server : MYSQL
Source Server Type : MySQL
Source Server Version : 80013
Source Host : localhost:3306
Source Schema : jsp_goods_management
Target Server Type : MySQL
Target Server Version : 80013
File Encoding : 65001
Date: 01/03/2022 14:34:48
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for admin
-- ----------------------------
DROP TABLE IF EXISTS `admin`;
CREATE TABLE `admin` (
`username` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL,
`password` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of admin
-- ----------------------------
INSERT INTO `admin` VALUES ('admin', 'admin');
-- ----------------------------
-- Table structure for goods
-- ----------------------------
DROP TABLE IF EXISTS `goods`;
CREATE TABLE `goods` (
`id` int(11) NOT NULL,
`name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`num` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL,
`address` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of goods
-- ----------------------------
INSERT INTO `goods` VALUES (1001, '方便面', '30', '辽宁沈阳');
INSERT INTO `goods` VALUES (1002, '果粒橙', '50', '广东深圳');
INSERT INTO `goods` VALUES (1003, '苹果', '80', '甘肃天水');
INSERT INTO `goods` VALUES (1004, '牛肉面', '100', '甘肃兰州');
SET FOREIGN_KEY_CHECKS = 1;
5. System screenshot
2. System display
1. Log in to the system
2. System home page
3. Add merchandise
4. Modify the product
3. Part of the code
AdminDaoImpl
package com.sjsq.dao.impl;
import com.sjsq.dao.AdminDao;
import com.sjsq.utils.DBUtil;
import com.sjsq.entity.Admin;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/**
* @author: shuijianshiqing
* @date: 2022-03-01
* @description: 登录系统实现
*/
public class AdminDaoImpl implements AdminDao {
/**
* 登录系统
* @param admin
* @return
*/
@Override
public Admin login(Admin admin) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.获取数据库连接
con = DBUtil.getConnection();
// 2.写sql
String sql = "select * from admin where username = ? and password = ?";
// 3.预编译
ps = con.prepareStatement(sql);
// 4.设置值
ps.setObject(1, admin.getUsername());
ps.setObject(2, admin.getPassword());
rs = ps.executeQuery();
Admin adminLogin = null;
if (rs.next()) {
adminLogin = new Admin();
// 从数据库中获取值到实体类的setter方法中
adminLogin.setUsername(rs.getString("username"));
adminLogin.setPassword(rs.getString("password"));
// 返回的是你查询出来的完整的对象
return adminLogin;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 关闭资源,避免出现异常
DBUtil.close(con, ps, rs);
}
return null;
}
}
GoodsDaoImpl
package com.sjsq.dao.impl;
import com.sjsq.dao.GoodsDao;
import com.sjsq.entity.Goods;
import com.sjsq.entity.Goods;
import com.sjsq.utils.DBUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
/**
* @author: shuijianshiqing
* @date: 2022-03-01
* @description:
*/
public class GoodsDaoImpl implements GoodsDao {
@Override
public List<Goods> selectAll(String sql, Object[] arr) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.连接数据库
con = DBUtil.getConnection();
// 2.预编译
ps = con.prepareStatement(sql);
if (arr != null) {
for (int i = 0; i < arr.length; i++) {
// 传入sql的参数,向上转型,某个栏位的查询
ps.setObject(i + 1, arr[i]);
}
}
// 3.执行sql
rs = ps.executeQuery();
// 4.保存查询出来的数据到list
List<Goods> list = new ArrayList<>();
while (rs.next()) {
Goods goods = new Goods();
goods.setId(rs.getInt("id"));
goods.setName(rs.getString("name"));
goods.setNum(rs.getString("num"));
goods.setAddress(rs.getString("address"));
list.add(goods);
}
return list;
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭链接,避免数据库连接过多
DBUtil.close(con, ps, rs);
}
return null;
}
@Override
public Goods selectGoods(Integer id) {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
// 1.连接数据库
con = DBUtil.getConnection();
// 2.预编译
String sql = "select * from goods where id = ?";
ps = con.prepareStatement(sql);
ps.setInt(1, id);
// 3.执行sql
rs = ps.executeQuery();
while (rs.next()) {
Goods goods = new Goods();
goods.setId(rs.getInt("id"));
goods.setName(rs.getString("name"));
goods.setNum(rs.getString("num"));
goods.setAddress(rs.getString("address"));
return goods;
}
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
} finally {
// 关闭资源,避免出现异常
DBUtil.close(con, ps, rs);
}
return null;
}
@Override
public boolean addGoods(Goods goods) {
String sql = "insert into goods values (?,?,?,?)";
List<Object> list = new ArrayList<Object>();
list.add(goods.getId());
list.add(goods.getName());
list.add(goods.getNum());
list.add(goods.getAddress());
boolean flag = DBUtil.addUpdateDelete(sql, list.toArray());
if (flag) {
return true;
} else {
return false;
}
}
@Override
public boolean updateGoods(Goods goods) {
String sql = "update goods set name=?,num=?,address=? where id=?";
List<Object> list = new ArrayList<Object>();
list.add(goods.getName());
list.add(goods.getNum());
list.add(goods.getAddress());
// 注意id在最后面
list.add(goods.getId());
boolean flag = DBUtil.addUpdateDelete(sql, list.toArray());
if (flag) {
return true;
} else {
return false;
}
}
@Override
public boolean deleteGoods(Integer id) {
String sql = "delete from goods where id=?";
List<Object> list = new ArrayList<Object>();
list.add(id);
boolean flag = DBUtil.addUpdateDelete(sql, list.toArray());
if (flag) {
return true;
} else {
return false;
}
}
}
goods-add.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>新增商品</title>
<link rel="stylesheet" type="text/css" href="css/common.css">
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<h1>新增商品</h1>
<hr/>
<div id="before">
<a href="javascript: window.history.go(-1)">返回上一级</a>
</div>
</br>
<form action="goods-add-do.jsp" method="post" name="addForm">
<div>
<tr>
<label>商品编号:</label>
<input type="text" name="id" id="id" placeholder="请输入商品编号">
</tr>
</div>
<div>
<tr>
<label>商品名称:</label>
<input type="text" name="name" id="name" placeholder="请输入商品名称">
</tr>
</div>
<div>
<tr>
<label>商品库存:</label>
<input type="text" name="num" id="num" placeholder="请输入商品库存">
</tr>
</div>
<div>
<tr>
<label>商品地址:</label>
<input type="text" name="address" id="address" placeholder="请输入商品地址">
</tr>
</div>
<br>
<div id="submit">
<tr>
<button type="submit" onclick="return checkForm()">添加</button>
<button type="reset">重置</button>
</tr>
</div>
</form>
<script type="text/javascript">
function checkForm() {
var id = addForm.id.value;
var name = addForm.name.value;
// 商品编号和商品名称不能为空
if (id == "" || id == null) {
alert("请输入商品编号");
addForm.id.focus();
return false;
} else if (name == "" || name == null) {
alert("请输入商品名称");
addForm.name.focus();
return false;
}
return true;
}
</script>
<%-- 底部 --%>
<jsp:include page="bottom.jsp"/>
</body>
</html>
goods-add-do.jsp
<%@ page import="com.sjsq.entity.Goods" %>
<%@ page import="com.sjsq.service.GoodsService" %>
<%@ page import="com.sjsq.service.impl.GoodsServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>新增商品</title>
</head>
<body>
<%
// 设置获取注册时的编码为UTF-8
request.setCharacterEncoding("UTF-8");
//获取teacher-add.jsp页面提交的账号和密码,注意传过来的是字符串需要进行转化为对应的类型
Integer id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String num = request.getParameter("num");
String address = request.getParameter("address");
// 将信息保存到实体类中
Goods goods = new Goods();
goods.setId(id);
goods.setName(name);
goods.setNum(num);
goods.setAddress(address);
System.out.println("添加的商品信息");
System.out.println(goods);
// 将数据写入到数据库
GoodsService goodsService = new GoodsServiceImpl();
boolean flag = goodsService.addGoods(goods);
if(flag){
response.sendRedirect("main.jsp");
}else{
response.sendRedirect("error.jsp");
}
%>
</body>
</html>
goods-update.jsp
<%@ page import="com.sjsq.entity.Goods" %>
<%@ page import="com.sjsq.service.GoodsService" %>
<%@ page import="com.sjsq.service.impl.GoodsServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改商品</title>
<link rel="stylesheet" type="text/css" href="css/common.css">
</head>
<body>
<%-- 头部 --%>
<jsp:include page="top.jsp"/>
<h1>修改商品</h1>
<hr/>
<%
//获取main.jsp页面的id
Integer id = Integer.parseInt(request.getParameter("id"));
GoodsService goodsService = new GoodsServiceImpl();
Goods goods = goodsService.selectGoods(id);
%>
<div>
<a href="javascript: window.history.go(-1)">返回上一级</a>
</div>
</br>
<form action="goods-update-do.jsp" method="post" id="addForm">
<div>
<%-- 这里教职工号不能修改 --%>
<tr>
<label>商品编号:</label>
<input type="text" name="id" id="id" placeholder="请输入商品编号" value="<%=goods.getId()%>" readonly="true">
</tr>
</div>
<div>
<tr>
<label>商品名称:</label>
<input type="text" name="name" id="name" placeholder="请输入商品名称" value="<%=goods.getName()%>" autofocus="autofocus">
</tr>
</div>
<div>
<tr>
<label>商品库存:</label>
<input type="text" name="num" id="num" placeholder="请输入商品库存" value="<%=goods.getNum()%>">
</tr>
</div>
<div>
<tr>
<label>商品地址:</label>
<input type="text" name="address" id="address" placeholder="请输入商品地址" value="<%=goods.getAddress()%>">
</tr>
</div>
<br>
<div id="submit">
<tr>
<button type="submit" onclick="return checkForm()">修改</button>
<button type="reset">重置</button>
</tr>
</div>
</form>
<script type="text/javascript">
function checkForm() {
var id = addForm.id.value;
var name = addForm.name.value;
// 商品编号和商品名称不能为空
if (id == "" || id == null) {
alert("请输入商品编号");
addForm.id.focus();
return false;
} else if (name == "" || name == null) {
alert("请输入商品名称");
addForm.name.focus();
return false;
}
return true;
}
</script>
<%-- 底部 --%>
<jsp:include page="bottom.jsp"/>
</body>
</html>
goods-update-do.jsp
<%@ page import="com.sjsq.entity.Goods" %>
<%@ page import="com.sjsq.service.GoodsService" %>
<%@ page import="com.sjsq.service.impl.GoodsServiceImpl" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>修改商品</title>
</head>
<body>
<%
// 设置获取注册时的编码为UTF-8
request.setCharacterEncoding("UTF-8");
//获取teacher-update.jsp页面提交的账号和密码,注意传过来的是字符串需要进行转化为对应的类型
Integer id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String num = request.getParameter("num");
String address = request.getParameter("address");
// 将信息保存到实体类中
Goods goods = new Goods();
goods.setId(id);
goods.setName(name);
goods.setNum(num);
goods.setAddress(address);
System.out.println("修改的商品信息");
System.out.println(goods);
// 将数据写入到数据库
GoodsService goodsService = new GoodsServiceImpl();
boolean flag = goodsService.updateGoods(goods);
if(flag){
response.sendRedirect("main.jsp");
}else{
response.sendRedirect("error.jsp");
}
%>
</body>
</html>
4. Other
1. More systems
Java+JSP system series implementation
Java+JSP Realization of Student Book Management System
Java+JSP Realization of Student Information Management System
Java+JSP Realization of User Information Management System
Java+JSP Realization of Teacher Information Management System
Java+JSP Realization of Student Dormitory Information Management System
Java+Servlet system series implementation
Java+Servlet+JSP Realization of Airline Booking System
Java+Servlet+JSP Realization of News Release System
Java+Servlet+JSP Student Dormitory Management System
Java+Servlet+JSP Realization of Book Management System
Java+Servlet+JSP Realization of Parking Lot Management System
Java+Servlet+JSP Realization of Housing Rental Management System
Java+Servlet+JSP Realization of Student Information Management System
Java+Servlet+JSP to realize student course selection management system
Java+Servlet+JSPl realizes the student's course selection and sign-in system
Java+Servlet+JSP realizes pet clinic management system
Java+Servlet+JSP realizes student achievement management system-1
Java+Servlet+JSP realizes student achievement management system-2
Java+SSM system series implementation
Java+SSM+JSP to realize online examination system
Java+SSM+JSP to realize pet mall system
Java+SSM+JSP Realization of Supermarket Management System
Java+SSM+JSP realizes student achievement management system
Java+SSM+JSP Realization of Student Information Management System
Java+SSM+JSP Realization of Drug Information Management System
Java+SSM+JSP+Maven to realize online bookstore system
Java+SSM+JSP+Maven to realize school education management system
Java+SSH system series implementation
Java+SSH+JSP Realization of Online Exam System
Java+SSH+JSP Realization of Hospital Online Registration System
Java+Springboot system series implementation
Java+Springboot+H-ui+Maven to realize marketing management system
Java+Springboot+Bootstrap+Maven to realize online mall system
Java+Springboot+Bootstrap+Maven realizes scenic tourism management system
1. For more JavaWeb systems, please pay attention to the column.
2. For more JavaSwing systems, please pay attention to the column.
2. Source code download
sql is under the sql folder
Java+JSP+Mysql realizes Web commodity information management system
3. Run the project
How IDEA Imports JavaWeb Project Super Detailed Video Tutorial
4. Remarks
If there is any infringement, please contact me to delete it.
5. Support Bloggers
If you think this article is helpful to you, please like, follow and favorite. wish you a happy life!