2025春开学考——仓库管理系统(总结)

news/2025/2/23 20:57:56/文章来源:https://www.cnblogs.com/qiixunlu/p/18732853

一、数据库设计:

User类

点击查看代码
drop table if exists tb_user;
create table tb_user(userID varchar(20),password varchar(20),position int
);
warehouse类
点击查看代码
CREATE TABLE warehouse (warehouseCode VARCHAR(50) UNIQUE NOT NULL ,  -- 仓库编码,唯一且不能为空warehouseName VARCHAR(100) NOT NULL,        -- 仓库名称,不能为空location VARCHAR(200),                      -- 仓库地址capacity DECIMAL(10, 2),                    -- 仓库容量,可存储数值,例如存储货物的重量或体积contactPerson VARCHAR(50),                 -- 仓库联系人contactPhone VARCHAR(20)                   -- 联系人电话
);
material_category类
点击查看代码
CREATE TABLE material_category (materialCode VARCHAR(50) NOT NULL UNIQUE PRIMARY KEY,materialName VARCHAR(100) NOT NULL,specification VARCHAR(100),material VARCHAR(100),-- 可根据需求添加其他字段,如备注等remarks TEXT
);
material_ledger_detail类
点击查看代码
CREATE TABLE material_ledger_detail (-- 台账编号,作为主键,唯一标识每条记录ledgerId VARCHAR(12) PRIMARY KEY NOT NULL,-- 物资编码,用于关联物资类别表,不允许为空materialCode VARCHAR(50) NOT NULL,-- 操作类别,使用 ENUM 类型限制为 '入库' 或 '出库',不允许为空operationType ENUM('入库', '出库') NOT NULL,-- 物资数量,使用 DECIMAL 类型存储,精度为 10,小数位为 2,不允许为空quantity DECIMAL(10, 2) NOT NULL,-- 计量单位,如 '个'、'箱' 等,不允许为空unit VARCHAR(20) NOT NULL,-- 存放地点(仓库号),不允许为空storageLocation VARCHAR(20) NOT NULL,-- 操作日期,记录操作发生的时间,默认值为当前时间operationDate TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

二、分别对应的pojo设计
User类

点击查看代码
package com.QixunQiu.pojo;public class User {private String userID;private String password;private Integer position;// Getters and Setterspublic String getUserID() {return userID;}public void setUserID(String userID) {this.userID = userID;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public Integer getPosition() {return position;}public void setPosition(Integer position) {this.position = position;}// toString method@Overridepublic String toString() {return "TbUser{" +"userID='" + userID + '\'' +", password='" + password + '\'' +", position=" + position +'}';}
}
Warehouse类
点击查看代码
package com.QixunQiu.pojo;import java.math.BigDecimal;public class Warehouse {private String warehouseCode;  // 仓库编码private String warehouseName; // 仓库名称private String location;      // 仓库地址private BigDecimal capacity;  // 仓库容量private String contactPerson; // 仓库联系人private String contactPhone;  // 联系人电话// Getters and Setterspublic String getWarehouseCode() {return warehouseCode;}public void setWarehouseCode(String warehouseCode) {this.warehouseCode = warehouseCode;}public String getWarehouseName() {return warehouseName;}public void setWarehouseName(String warehouseName) {this.warehouseName = warehouseName;}public String getLocation() {return location;}public void setLocation(String location) {this.location = location;}public BigDecimal getCapacity() {return capacity;}public void setCapacity(BigDecimal capacity) {this.capacity = capacity;}public String getContactPerson() {return contactPerson;}public void setContactPerson(String contactPerson) {this.contactPerson = contactPerson;}public String getContactPhone() {return contactPhone;}public void setContactPhone(String contactPhone) {this.contactPhone = contactPhone;}// toString method@Overridepublic String toString() {return "Warehouse{" +"warehouseCode='" + warehouseCode + '\'' +", warehouseName='" + warehouseName + '\'' +", location='" + location + '\'' +", capacity=" + capacity +", contactPerson='" + contactPerson + '\'' +", contactPhone='" + contactPhone + '\'' +'}';}
}
MaterialCategory类
点击查看代码
package com.QixunQiu.pojo;public class MaterialCategory {private String materialCode;  // 物料编码,主键private String materialName; // 物料名称private String specification; // 规格private String material; // 物料类型private String remarks; // 备注// Getters and Setterspublic String getMaterialCode() {return materialCode;}public void setMaterialCode(String materialCode) {this.materialCode = materialCode;}public String getMaterialName() {return materialName;}public void setMaterialName(String materialName) {this.materialName = materialName;}public String getSpecification() {return specification;}public void setSpecification(String specification) {this.specification = specification;}public String getMaterial() {return material;}public void setMaterial(String material) {this.material = material;}public String getRemarks() {return remarks;}public void setRemarks(String remarks) {this.remarks = remarks;}// toString method@Overridepublic String toString() {return "MaterialCategory{" +"materialCode='" + materialCode + '\'' +", materialName='" + materialName + '\'' +", specification='" + specification + '\'' +", material='" + material + '\'' +", remarks='" + remarks + '\'' +'}';}
}
MaterialLedgerDetail类
点击查看代码
package com.QixunQiu.pojo;import java.math.BigDecimal;
import java.sql.Timestamp;public class MaterialLedgerDetail {private String ledgerId; // 台账编号,主键private String materialCode; // 物资编码private String operationType; // 操作类别:'入库' 或 '出库'private BigDecimal quantity; // 物资数量private String unit; // 计量单位private String storageLocation; // 存放地点(仓库号)private Timestamp operationDate; // 操作日期,默认为当前时间// Getters and Setterspublic String getLedgerId() {return ledgerId;}public void setLedgerId(String ledgerId) {this.ledgerId = ledgerId;}public String getMaterialCode() {return materialCode;}public void setMaterialCode(String materialCode) {this.materialCode = materialCode;}public String getOperationType() {return operationType;}public void setOperationType(String operationType) {this.operationType = operationType;}public BigDecimal getQuantity() {return quantity;}public void setQuantity(BigDecimal quantity) {this.quantity = quantity;}public String getUnit() {return unit;}public void setUnit(String unit) {this.unit = unit;}public String getStorageLocation() {return storageLocation;}public void setStorageLocation(String storageLocation) {this.storageLocation = storageLocation;}public Timestamp getOperationDate() {return operationDate;}public void setOperationDate(Timestamp operationDate) {this.operationDate = operationDate;}// toString method@Overridepublic String toString() {return "MaterialLedgerDetail{" +"ledgerId='" + ledgerId + '\'' +", materialCode='" + materialCode + '\'' +", operationType='" + operationType + '\'' +", quantity=" + quantity +", unit='" + unit + '\'' +", storageLocation='" + storageLocation + '\'' +", operationDate=" + operationDate +'}';}
}
三、所有的Mapper接口与对应的映射.xml User类接口
点击查看代码
package com.QixunQiu.mapper;import com.QixunQiu.pojo.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;import java.util.List;public interface UserMapper {@Select("select * from tb_user where UserID = #{UserID} and Password = #{Password}")User select(@Param("UserID") String UserID, @Param("Password")  String Password);int updatePassword(User user);void addUser(User user);List<User> selectALL();@Select("select * from tb_user where UserID = #{UserID} ")User selectByUserID(@Param("UserID") String UserID);void deleteByUserID(String UserID);
}
User.xml
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.QixunQiu.mapper.UserMapper"><insert id="addUser">insert into tb_user (UserID, Password)values (#{UserID}, #{Password});</insert><update id="updatePassword" >update tb_user<set><if test="Password != null and Password != ''">Password = #{Password},</if></set>where UserID = #{UserID};</update><delete id="deleteByUserID">delete from tb_user where UserID = #{UserID}</delete><select id="selectALL" resultType="com.QixunQiu.pojo.User">select *from tb_user ;</select>
</mapper>
Warehouse类接口
点击查看代码
package com.QixunQiu.mapper;import com.QixunQiu.pojo.Warehouse;import java.util.List;public interface WarehouseMapper {void addWarehouse(Warehouse warehouse);List<Warehouse> selectAllWarehouse();Warehouse selectWarehouseById(String id);int updateWarehouse(Warehouse warehouse);void deleteWarehouse(String id);
}
WarehouseMapper.xml
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.QixunQiu.mapper.WarehouseMapper"><insert id="addWarehouse" parameterType="com.QixunQiu.pojo.Warehouse">INSERT INTO warehouse (warehouseCode,warehouseName,location,capacity,contactPerson,contactPhone) VALUES (#{warehouseCode},#{warehouseName},#{location},#{capacity},#{contactPerson},#{contactPhone})</insert><update id="updateWarehouse" parameterType="com.QixunQiu.pojo.Warehouse">UPDATE warehouseSETwarehouseName = #{warehouseName},location = #{location},capacity = #{capacity},contactPerson = #{contactPerson},contactPhone = #{contactPhone}WHERE warehouseCode = #{warehouseCode}</update><delete id="deleteWarehouse">delete from warehouse where warehouseCode=#{warehouseCode};</delete><select id="selectAllWarehouse" resultType="com.QixunQiu.pojo.Warehouse">select *from warehouse ;</select><select id="selectWarehouseById" resultType="com.QixunQiu.pojo.Warehouse">select *from warehouse where warehouseCode=#{warehouseCode};</select></mapper>
MaterialCategory接口
点击查看代码
package com.QixunQiu.mapper;import com.QixunQiu.pojo.MaterialCategory;import java.util.List;public interface MaterialCategoryMapper {void addMaterialCategory(MaterialCategory materialCategory);List<MaterialCategory> selectAllMaterialCategory();MaterialCategory selectMaterialCategoryById(String id);int updateMaterialCategory(MaterialCategory materialCategory);void deleteMaterialCategory(String id);
}
MaterialCategoryMapper.xml
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.QixunQiu.mapper.MaterialCategoryMapper"><insert id="addMaterialCategory" parameterType="com.QixunQiu.pojo.MaterialCategory">INSERT INTO material_category (materialCode,materialName,specification,material,remarks) VALUES (#{materialCode},#{materialName},#{specification},#{material},#{remarks})</insert><update id="updateMaterialCategory" parameterType="com.QixunQiu.pojo.MaterialCategory">UPDATE material_categorySETmaterialName = #{materialName},specification = #{specification},material = #{material},remarks = #{remarks}WHERE materialCode = #{materialCode}</update><delete id="deleteMaterialCategory">delete from material_category where materialCode= #{materialCode};</delete><select id="selectAllMaterialCategory" resultType="com.QixunQiu.pojo.MaterialCategory">select *from material_category;</select><select id="selectMaterialCategoryById" resultType="com.QixunQiu.pojo.MaterialCategory">select *from material_category where materialCode=#{materialCode};</select></mapper>
MaterialLedgerDetail接口
点击查看代码
package com.QixunQiu.mapper;import com.QixunQiu.pojo.MaterialLedgerDetail;import java.util.List;public interface MaterialLedgerDetailMapper {void addMaterialLedgerDetail(MaterialLedgerDetail materialLedgerDetail);List<MaterialLedgerDetail> getMaterialLedgerDetailById(String id);
}
MaterialLedgerDetailMapper.xml
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.QixunQiu.mapper.MaterialLedgerDetailMapper"><insert id="addMaterialLedgerDetail" parameterType="com.QixunQiu.pojo.MaterialLedgerDetail">INSERT INTO material_ledger_detail (ledgerId,materialCode,operationType,quantity,unit,storageLocation,operationDate) VALUES (#{ledgerId},#{materialCode},#{operationType},#{quantity},#{unit},#{storageLocation},#{operationDate, jdbcType=TIMESTAMP})</insert><select id="getMaterialLedgerDetailById" resultType="com.QixunQiu.pojo.MaterialLedgerDetail">select * from material_ledger_detail where materialCode=#{materialCode};</select>
</mapper>
四、Service UserService
点击查看代码
package com.QixunQiu.service;import com.QixunQiu.mapper.UserMapper;
import com.QixunQiu.pojo.User;
import com.QixunQiu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;import java.util.List;public class UserService {SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();public User selectUser(String UserID, String Password) {SqlSession sqlSession = sqlSessionFactory.openSession();UserMapper userMapper = sqlSession.getMapper(UserMapper.class);User user = userMapper.select(UserID, Password);sqlSession.close();return user;}public User selectUserByID(String UserID) {SqlSession sqlSession = sqlSessionFactory.openSession();UserMapper userMapper = sqlSession.getMapper(UserMapper.class);User user = userMapper.selectByUserID(UserID);sqlSession.close();return user;}public List<User> selectAllUser() {SqlSession sqlSession = sqlSessionFactory.openSession();UserMapper userMapper = sqlSession.getMapper(UserMapper.class);List<User> users=userMapper.selectALL();sqlSession.close();return users;}public void deleteUser(String UserID) {SqlSession sqlSession = sqlSessionFactory.openSession();UserMapper userMapper = sqlSession.getMapper(UserMapper.class);System.out.println(UserID);userMapper.deleteByUserID(UserID);sqlSession.commit();sqlSession.close();}public void  updatePassword(User user) {SqlSession sqlSession = sqlSessionFactory.openSession();UserMapper userMapper = sqlSession.getMapper(UserMapper.class);System.out.println("465652");userMapper.updatePassword(user);sqlSession.commit();sqlSession.close();}public void addUser(User user) {SqlSession sqlSession = sqlSessionFactory.openSession();UserMapper userMapper = sqlSession.getMapper(UserMapper.class);userMapper.addUser(user);sqlSession.commit();sqlSession.close();}
}
WarehouseService
点击查看代码
package com.QixunQiu.service;import com.QixunQiu.mapper.WarehouseMapper;
import com.QixunQiu.pojo.Warehouse;
import com.QixunQiu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;import java.util.List;public class WarehouseService {SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();public void add(Warehouse warehouse) {SqlSession sqlSession = sqlSessionFactory.openSession();WarehouseMapper warehouseMapper = sqlSession.getMapper(WarehouseMapper.class);warehouseMapper.addWarehouse(warehouse);sqlSession.commit();sqlSession.close();}public List<Warehouse> getAll() {SqlSession sqlSession = sqlSessionFactory.openSession();WarehouseMapper warehouseMapper = sqlSession.getMapper(WarehouseMapper.class);List<Warehouse> warehouseList=warehouseMapper.selectAllWarehouse();sqlSession.close();return warehouseList;}public Warehouse getWarehouseById(String id) {SqlSession sqlSession = sqlSessionFactory.openSession();WarehouseMapper warehouseMapper = sqlSession.getMapper(WarehouseMapper.class);Warehouse warehouse=warehouseMapper.selectWarehouseById(id);sqlSession.close();return warehouse;}public void update(Warehouse warehouse) {SqlSession sqlSession = sqlSessionFactory.openSession();WarehouseMapper warehouseMapper = sqlSession.getMapper(WarehouseMapper.class);warehouseMapper.updateWarehouse(warehouse);sqlSession.commit();sqlSession.close();}public void delete(String id) {SqlSession sqlSession = sqlSessionFactory.openSession();WarehouseMapper warehouseMapper = sqlSession.getMapper(WarehouseMapper.class);System.out.println(id);warehouseMapper.deleteWarehouse(id);sqlSession.commit();sqlSession.close();}
}
MaterialCategoryService
点击查看代码
package com.QixunQiu.service;import com.QixunQiu.mapper.MaterialCategoryMapper;
import com.QixunQiu.pojo.MaterialCategory;
import com.QixunQiu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;import java.util.List;public class MaterialCategoryService {SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();public void add(MaterialCategory materialCategory) {SqlSession sqlSession = sqlSessionFactory.openSession();MaterialCategoryMapper materialCategoryMapper = sqlSession.getMapper(MaterialCategoryMapper.class);materialCategoryMapper.addMaterialCategory(materialCategory);sqlSession.commit();sqlSession.close();}public List<MaterialCategory> findAll() {SqlSession sqlSession = sqlSessionFactory.openSession();MaterialCategoryMapper materialCategoryMapper = sqlSession.getMapper(MaterialCategoryMapper.class);List<MaterialCategory> materialCategoryList=materialCategoryMapper.selectAllMaterialCategory();sqlSession.close();return materialCategoryList;}public MaterialCategory findById(String id) {SqlSession sqlSession = sqlSessionFactory.openSession();MaterialCategoryMapper materialCategoryMapper = sqlSession.getMapper(MaterialCategoryMapper.class);MaterialCategory materialCategory = materialCategoryMapper.selectMaterialCategoryById(id);sqlSession.close();return materialCategory;}public void update(MaterialCategory materialCategory) {SqlSession sqlSession = sqlSessionFactory.openSession();MaterialCategoryMapper materialCategoryMapper = sqlSession.getMapper(MaterialCategoryMapper.class);materialCategoryMapper.updateMaterialCategory(materialCategory);sqlSession.commit();sqlSession.close();}public void delete(String id) {SqlSession sqlSession = sqlSessionFactory.openSession();MaterialCategoryMapper materialCategoryMapper = sqlSession.getMapper(MaterialCategoryMapper.class);materialCategoryMapper.deleteMaterialCategory(id);sqlSession.commit();sqlSession.close();}
}
MaterialLedgerDetailService
点击查看代码
package com.QixunQiu.service;import com.QixunQiu.mapper.MaterialLedgerDetailMapper;
import com.QixunQiu.pojo.MaterialLedgerDetail;
import com.QixunQiu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;import java.util.List;public class MaterialLedgerDetailService {SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();public void add(MaterialLedgerDetail materialLedgerDetail) {SqlSession sqlSession = sqlSessionFactory.openSession();MaterialLedgerDetailMapper mapper = sqlSession.getMapper(MaterialLedgerDetailMapper.class);mapper.addMaterialLedgerDetail(materialLedgerDetail);sqlSession.commit();sqlSession.close();}public List<MaterialLedgerDetail> selectByPrimaryKey(String id) {SqlSession sqlSession = sqlSessionFactory.openSession();MaterialLedgerDetailMapper mapper = sqlSession.getMapper(MaterialLedgerDetailMapper.class);List<MaterialLedgerDetail> materialLedgerDetail=mapper.getMaterialLedgerDetailById(id);sqlSession.close();return materialLedgerDetail;}
}
五、Servlet addMaterialCategoryServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.MaterialCategory;
import com.QixunQiu.service.MaterialCategoryService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/addMaterialCategoryServlet")
public class addMaterialCategoryServlet extends HttpServlet {MaterialCategoryService mcs = new MaterialCategoryService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");// 从表单中获取数据String materialCode = request.getParameter("materialCode");String materialName = request.getParameter("materialName");String specification = request.getParameter("specification");String material = request.getParameter("material");String remarks = request.getParameter("remarks");// 创建 MaterialCategory 对象并填充数据MaterialCategory category = new MaterialCategory();category.setMaterialCode(materialCode);category.setMaterialName(materialName);category.setSpecification(specification);category.setMaterial(material);category.setRemarks(remarks);mcs.add(category);HttpSession session = request.getSession();List<MaterialCategory> materialCategoryList=mcs.findAll();session.setAttribute("materialCategoryList", materialCategoryList);request.getRequestDispatcher("/materialcategory.jsp").forward(request, response);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
addMaterialLedgerDetailServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.MaterialLedgerDetail;
import com.QixunQiu.service.MaterialCategoryService;
import com.QixunQiu.service.MaterialLedgerDetailService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.*;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;@WebServlet("/addMaterialLedgerDetailServlet")
public class addMaterialLedgerDetailServlet extends HttpServlet {private MaterialLedgerDetailService mlds = new MaterialLedgerDetailService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");// 获取表单数据String ledgerId = generateID();String materialCode = request.getParameter("materialCode");String operationType = request.getParameter("operationType");BigDecimal quantity = new BigDecimal(request.getParameter("quantity"));String unit = request.getParameter("unit");String storageLocation = request.getParameter("storageLocation");String operationDateStr = request.getParameter("operationDate");// 将字符串日期转换为 Timestamp(如果用户未选择日期,则使用当前时间)Timestamp operationDate = null;if (operationDateStr != null && !operationDateStr.isEmpty()) {operationDate = Timestamp.valueOf(operationDateStr);} else {operationDate = new Timestamp(System.currentTimeMillis());}// 创建 MaterialLedgerDetail 对象MaterialLedgerDetail detail = new MaterialLedgerDetail();detail.setLedgerId(ledgerId);detail.setMaterialCode(materialCode);detail.setOperationType(operationType);detail.setQuantity(quantity);detail.setUnit(unit);detail.setStorageLocation(storageLocation);detail.setOperationDate(operationDate);mlds.add(detail);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}private int sequenceNumber = 1;public synchronized String generateID() {// 获取当前日期Date now = new Date();SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");String dateStr = sdf.format(now);// 读取或初始化sequenceNumberif (sequenceNumber == 1) {File file = new File("MaterialLedgerDetail.txt");if (file.exists()) {try {BufferedReader reader = new BufferedReader(new FileReader(file));String line = reader.readLine();sequenceNumber = Integer.parseInt(line);reader.close();} catch (IOException e) {e.printStackTrace();}}}// 组合房产编号String sequenceStr = String.format("%04d", sequenceNumber++);String houseID = dateStr + sequenceStr;// 更新sequenceNumber到文件try {BufferedWriter writer = new BufferedWriter(new FileWriter("MaterialLedgerDetail.txt"));writer.write(String.valueOf(sequenceNumber));writer.close();} catch (IOException e) {e.printStackTrace();}return houseID;}
}
addWarehouseServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.Warehouse;
import com.QixunQiu.service.WarehouseService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;@WebServlet("/addWarehouseServlet")
public class addWarehouseServlet extends HttpServlet {private WarehouseService warehouseService = new WarehouseService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// 设置请求和响应的编码为 UTF-8request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");// 从表单中获取数据String warehouseCode = request.getParameter("warehouseCode");String warehouseName = request.getParameter("warehouseName");String location = request.getParameter("location");String capacityStr = request.getParameter("capacity");String contactPerson = request.getParameter("contactPerson");String contactPhone = request.getParameter("contactPhone");// 创建 Warehouse 对象并填充数据Warehouse warehouse = new Warehouse();warehouse.setWarehouseCode(warehouseCode);warehouse.setWarehouseName(warehouseName);warehouse.setLocation(location);warehouse.setCapacity(capacityStr != null && !capacityStr.isEmpty() ? new BigDecimal(capacityStr) : null);warehouse.setContactPerson(contactPerson);warehouse.setContactPhone(contactPhone);// 调用服务层方法添加仓库warehouseService.add(warehouse);HttpSession session = request.getSession();List<Warehouse> warehouseList=warehouseService.getAll();session.setAttribute("warehouseList", warehouseList);request.getRequestDispatcher("/warehouse.jsp").forward(request,response);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// 将 POST 请求转发到 doGet 方法处理this.doGet(request, response);}
}
DeleteMaterialCategoryServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.MaterialCategory;
import com.QixunQiu.pojo.MaterialLedgerDetail;
import com.QixunQiu.service.MaterialCategoryService;
import com.QixunQiu.service.MaterialLedgerDetailService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/DeleteMaterialCategoryServlet")
public class DeleteMaterialCategoryServlet extends HttpServlet {private MaterialCategoryService mcs = new MaterialCategoryService();private MaterialLedgerDetailService mlds = new MaterialLedgerDetailService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");String id = request.getParameter("id");HttpSession session = request.getSession();List<MaterialCategory> materialCategoryList=mcs.findAll();// 查询物料台账明细信息List<MaterialLedgerDetail> materialLedgerDetail = mlds.selectByPrimaryKey(id);if (!materialLedgerDetail.isEmpty()) {System.out.println("dwdwdwd");// 如果物料台账明细存在,说明该物料编码已被使用,不能编辑response.getWriter().write("<script>alert('该物料已存在于台账明细中,无法编辑!');window.location.href='" + request.getContextPath() + "/selectAllMaterialCategory';</script>");} else {// 如果物料台账明细不存在,可以编辑mcs.delete(id);session.setAttribute("materialCategoryList", materialCategoryList);request.getRequestDispatcher("/materialcategory.jsp").forward(request, response);}}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
DeleteWarehouseServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.Warehouse;
import com.QixunQiu.service.WarehouseService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/DeleteWarehouseServlet")
public class DeleteWarehouseServlet extends HttpServlet {private WarehouseService warehouseService = new WarehouseService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");String id=request.getParameter("id");//System.out.println(id);warehouseService.delete(id);HttpSession session = request.getSession();List<Warehouse> warehouseList=warehouseService.getAll();session.setAttribute("warehouseList", warehouseList);request.getRequestDispatcher("/warehouse.jsp").forward(request,response);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
LoginServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.User;
import com.QixunQiu.service.UserService;import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {private UserService userService = new UserService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");String UserID = request.getParameter("UserID");String Password = request.getParameter("Password");User user =userService.selectUser(UserID, Password);response.setContentType("text/html;charset=utf-8");PrintWriter writer = response.getWriter();//3. 判断user释放为nullif(user != null){// 登陆成功writer.write("登陆成功");HttpSession session = request.getSession();session.setAttribute("user", user);request.getRequestDispatcher("/index.jsp").forward(request,response);}else {// 登陆失败writer.write("登陆失败");}}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
selectAllMaterialCategory
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.MaterialCategory;
import com.QixunQiu.service.MaterialCategoryService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/selectAllMaterialCategory")
public class selectAllMaterialCategory extends HttpServlet {MaterialCategoryService mcs = new MaterialCategoryService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");HttpSession session = request.getSession();List<MaterialCategory> materialCategoryList=mcs.findAll();session.setAttribute("materialCategoryList", materialCategoryList);request.getRequestDispatcher("/materialcategory.jsp").forward(request, response);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
selectAllWarehouse
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.Warehouse;
import com.QixunQiu.service.WarehouseService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/selectAllWarehouse")
public class selectAllWarehouse extends HttpServlet {private WarehouseService warehouseService = new WarehouseService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");HttpSession session = request.getSession();List<Warehouse> warehouseList=warehouseService.getAll();session.setAttribute("warehouseList", warehouseList);request.getRequestDispatcher("/warehouse.jsp").forward(request,response);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
ToEditMaterialCategoryServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.MaterialCategory;
import com.QixunQiu.pojo.MaterialLedgerDetail;
import com.QixunQiu.service.MaterialCategoryService;
import com.QixunQiu.service.MaterialLedgerDetailService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/ToEditMaterialCategoryServlet")
public class ToEditMaterialCategoryServlet extends HttpServlet {private MaterialCategoryService mcs = new MaterialCategoryService();private MaterialLedgerDetailService mlds = new MaterialLedgerDetailService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");HttpSession session = request.getSession();String ID = request.getParameter("ID");// 查询物料分类信息MaterialCategory materialCategory = mcs.findById(ID);// 查询物料台账明细信息List<MaterialLedgerDetail> materialLedgerDetail = mlds.selectByPrimaryKey(ID);if (!materialLedgerDetail.isEmpty()) {System.out.println("dwdwdwd");// 如果物料台账明细存在,说明该物料编码已被使用,不能编辑response.getWriter().write("<script>alert('该物料已存在于台账明细中,无法编辑!');window.location.href='" + request.getContextPath() + "/selectAllMaterialCategory';</script>");} else {// 如果物料台账明细不存在,可以编辑session.setAttribute("materialCategory", materialCategory);request.getRequestDispatcher("/updateMaterialCategory.jsp").forward(request, response);}}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
ToFixWarehouseServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.Warehouse;
import com.QixunQiu.service.WarehouseService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/ToFixWarehouseServlet")
public class ToFixWarehouseServlet extends HttpServlet {private WarehouseService warehouseService = new WarehouseService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");response.setContentType("text/html;charset=UTF-8");HttpSession session = request.getSession();String id = request.getParameter("ID");System.out.println(id);Warehouse warehouse = warehouseService.getWarehouseById(id);session.setAttribute("warehouse", warehouse);request.getRequestDispatcher("/updateWarehouse.jsp").forward(request,response);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
updateMaterialCategoryServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.MaterialCategory;
import com.QixunQiu.service.MaterialCategoryService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;@WebServlet("/updateMaterialCategoryServlet")
public class updateMaterialCategoryServlet extends HttpServlet {MaterialCategoryService mcs = new MaterialCategoryService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html;charset=UTF-8");// 从表单中获取数据String materialCode = request.getParameter("materialCode");String materialName = request.getParameter("materialName");String specification = request.getParameter("specification");String material = request.getParameter("material");String remarks = request.getParameter("remarks");// 创建 MaterialCategory 对象并填充数据MaterialCategory category = new MaterialCategory();category.setMaterialCode(materialCode);category.setMaterialName(materialName);category.setSpecification(specification);category.setMaterial(material);category.setRemarks(remarks);mcs.update(category);HttpSession session = request.getSession();List<MaterialCategory> materialCategoryList=mcs.findAll();session.setAttribute("materialCategoryList", materialCategoryList);request.getRequestDispatcher("/materialcategory.jsp").forward(request, response);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
updateWarehouseServlet
点击查看代码
package com.QixunQiu.web;import com.QixunQiu.pojo.Warehouse;
import com.QixunQiu.service.WarehouseService;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.List;@WebServlet("/updateWarehouseServlet")
public class updateWarehouseServlet extends HttpServlet {private WarehouseService warehouseService = new WarehouseService();@Overrideprotected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {request.setCharacterEncoding("UTF-8");// 从表单中获取数据String warehouseCode = request.getParameter("warehouseCode");String warehouseName = request.getParameter("warehouseName");String location = request.getParameter("location");String capacityStr = request.getParameter("capacity");String contactPerson = request.getParameter("contactPerson");String contactPhone = request.getParameter("contactPhone");// 创建 Warehouse 对象并填充数据Warehouse warehouse = new Warehouse();warehouse.setWarehouseCode(warehouseCode);warehouse.setWarehouseName(warehouseName);warehouse.setLocation(location);warehouse.setCapacity(capacityStr != null && !capacityStr.isEmpty() ? new BigDecimal(capacityStr) : null);warehouse.setContactPerson(contactPerson);warehouse.setContactPhone(contactPhone);//System.out.println(warehouse);warehouseService.update(warehouse);HttpSession session = request.getSession();List<Warehouse> warehouseList=warehouseService.getAll();session.setAttribute("warehouseList", warehouseList);request.getRequestDispatcher("/warehouse.jsp").forward(request,response);}@Overrideprotected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {this.doGet(request, response);}
}
六、前端设计 addMaterialCategory.jsp
点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>添加物料分类信息</title><style>body {font-family: Arial, sans-serif;margin: 20px;}.container {max-width: 600px;margin: auto;padding: 20px;border: 1px solid #ccc;border-radius: 5px;}h2 {text-align: center;}form {display: flex;flex-direction: column;}label {margin-top: 10px;}input[type="text"],textarea {padding: 8px;margin-top: 5px;border: 1px solid #ccc;border-radius: 3px;}input[type="submit"] {margin-top: 15px;padding: 10px;background-color: #4CAF50;color: white;border: none;border-radius: 3px;cursor: pointer;}input[type="submit"]:hover {background-color: #45a049;}</style>
</head>
<body>
<div class="container"><h2>添加物料分类信息</h2><form action="${pageContext.request.contextPath}/addMaterialCategoryServlet" method="post"><label for="materialCode">物料编码(唯一):</label><input type="text" id="materialCode" name="materialCode" required><label for="materialName">物料名称:</label><input type="text" id="materialName" name="materialName" required><label for="specification">规格:</label><input type="text" id="specification" name="specification"><label for="material">物料类型:</label><input type="text" id="material" name="material"><label for="remarks">备注:</label><textarea id="remarks" name="remarks" rows="4"></textarea><input type="submit" value="添加物料分类"></form>
</div>
</body>
</html>
addMaterialLedgerDetail.jsp
点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>添加物料台账明细</title><style>body {font-family: Arial, sans-serif;margin: 20px;}.container {max-width: 600px;margin: auto;padding: 20px;border: 1px solid #ccc;border-radius: 5px;}h2 {text-align: center;}form {display: flex;flex-direction: column;}label {margin-top: 10px;}input[type="text"],input[type="number"],select {padding: 8px;margin-top: 5px;border: 1px solid #ccc;border-radius: 3px;}input[type="submit"] {margin-top: 15px;padding: 10px;background-color: #4CAF50;color: white;border: none;border-radius: 3px;cursor: pointer;}input[type="submit"]:hover {background-color: #45a049;}</style>
</head>
<body>
<div class="container"><h2>添加物料台账明细</h2><form action="${pageContext.request.contextPath}/addMaterialLedgerDetailServlet" method="post"><label for="materialCode">物资编码:</label><input type="text" id="materialCode" name="materialCode" required><label for="operationType">操作类别:</label><select id="operationType" name="operationType" required><option value="入库">入库</option><option value="出库">出库</option></select><label for="quantity">物资数量:</label><input type="number" id="quantity" name="quantity" step="0.01" required><label for="unit">计量单位:</label><input type="text" id="unit" name="unit" required><label for="storageLocation">存放地点(仓库号):</label><input type="text" id="storageLocation" name="storageLocation" required><input type="submit" value="添加物料台账明细"></form>
</div>
</body>
</html>
addWarehouse.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>添加仓库信息</title><style>body {font-family: Arial, sans-serif;margin: 20px;}.container {max-width: 600px;margin: auto;padding: 20px;border: 1px solid #ccc;border-radius: 5px;}h2 {text-align: center;}form {display: flex;flex-direction: column;}label {margin-top: 10px;}input[type="text"],input[type="tel"],input[type="number"] {padding: 8px;margin-top: 5px;border: 1px solid #ccc;border-radius: 3px;}input[type="submit"] {margin-top: 15px;padding: 10px;background-color: #4CAF50;color: white;border: none;border-radius: 3px;cursor: pointer;}input[type="submit"]:hover {background-color: #45a049;}</style>
</head>
<body>
<div class="container"><h2>添加仓库信息</h2><form action="${pageContext.request.contextPath}/addWarehouseServlet" method="post"><label for="warehouseCode">仓库编码(唯一):</label><input type="text" id="warehouseCode" name="warehouseCode" required><label for="warehouseName">仓库名称:</label><input type="text" id="warehouseName" name="warehouseName" required><label for="location">仓库地址:</label><input type="text" id="location" name="location"><label for="capacity">仓库容量(小数,例如:1000.50):</label><input type="number" id="capacity" name="capacity" step="0.01"><label for="contactPerson">联系人:</label><input type="text" id="contactPerson" name="contactPerson"><label for="contactPhone">联系电话:</label><input type="tel" id="contactPhone" name="contactPhone"><input type="submit" value="添加仓库"></form>
</div>
</body>
</html>
index.jsp
点击查看代码
<%@ page import="com.QixunQiu.pojo.User" %>
<%@ page import="java.util.Objects" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%User user = (User) session.getAttribute("user");// 使用user对象
%>
<!DOCTYPE html>
<html lang="en">
<head><meta charset="UTF-8"><title>仓库管理系统</title><style>body {font-family: Arial, sans-serif;margin: 0;padding: 0;background-color: #f4f4f9;}header {background-color: #4CAF50;color: white;padding: 10px 20px;text-align: center;}.container {display: flex;flex-direction: column;align-items: center;padding: 20px;}.button-group {display: flex;gap: 10px;margin-bottom: 20px;}button {padding: 10px 20px;font-size: 16px;background-color: #007BFF;color: white;border: none;border-radius: 5px;cursor: pointer;transition: background-color 0.3s ease;}button:hover {background-color: #0056b3;}</style>
</head>
<body>
<header><h1>仓库管理系统</h1>
</header>
<div class="container"><% if (user.getPosition() == 1 || user.getPosition() == 0) { %><div class="button-group"><button onclick="addHouse()">添加仓库</button><button onclick="checkHouse()">管理仓库</button><button onclick="addMaterialCategory()">添加物资类</button><button onclick="checkMaterial()">管理物资类</button></div><% } %><% if (user.getPosition() == 2 || user.getPosition() == 0) { %><div class="button-group"><button onclick="addMaterialLedgerDetail()">出入库操作</button><button onclick="window.location.href='统计查询.jsp'">统计查询</button></div><% } %>
</div>
<script>function addHouse() {window.location.href = "addWarehouse.jsp";}function checkHouse() {window.location.href = "/Cang/selectAllWarehouse";}function addMaterialCategory() {window.location.href = "addMaterialCategory.jsp";}function checkMaterial() {window.location.href = "/Cang/selectAllMaterialCategory";}function addMaterialLedgerDetail() {window.location.href = "addMaterialLedgerDetail.jsp";}
</script>
</body>
</html>
login.html
点击查看代码
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"><title>登录</title><style>body {font-family: 'Arial', sans-serif;background-color: #f4f4f4;margin: 0;padding: 0;display: flex;justify-content: center;align-items: center;height: 100vh;}#loginDiv {background-color: #fff;padding: 20px;border-radius: 8px;box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);width: 300px;}#loginMsg {text-align: center;color: #333;margin-bottom: 20px;}input[type="text"],input[type="password"] {width: 100%;padding: 10px;margin-bottom: 10px;border: 1px solid #ddd;border-radius: 4px;}input[type="submit"] {width: 100%;padding: 10px;background-color: #5cb85c;color: white;border: none;border-radius: 4px;cursor: pointer;}input[type="submit"]:hover {background-color: #4cae4c;}#subDiv {display: flex;justify-content: space-between;align-items: center;}a {color: #337ab7;text-decoration: none;}a:hover {text-decoration: underline;}</style>
</head><body>
<div id="loginDiv"><form action="/Cang/LoginServlet" method="post" id="form"><h1 id="loginMsg">欢迎使用差旅费报销管理信息系统</h1><p>用户名:<input id="UserID" name="UserID" type="text"></p><p>密码:<input id="Password" name="Password" type="password"></p><div id="subDiv"><input type="submit" class="button" value="登录"><a href="register.html">没有账号?点击注册</a></div></form>
</div>
</body></html>
materialcategory.jsp
点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %><!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>物料分类信息管理</title><script>function addMaterialCategory() {window.location.href = "addMaterialCategory.jsp";}</script><style>body {font-family: Arial, sans-serif;margin: 20px;}.container {max-width: 800px;margin: auto;padding: 20px;border: 1px solid #ccc;border-radius: 5px;}h2 {text-align: center;}table {width: 100%;border-collapse: collapse;margin-top: 20px;}th, td {border: 1px solid #ddd;padding: 8px;text-align: center;}th {background-color: #f2f2f2;}</style>
</head>
<body>
<div class="container"><h2>物料分类信息管理</h2><hr><table><tr><th>序号</th><th>物料编码</th><th>物料名称</th><th>规格</th><th>物料类型</th><th>备注</th><th>操作</th></tr><c:forEach items="${materialCategoryList}" var="category" varStatus="status"><tr><td>${status.count}</td><td>${category.materialCode}</td><td>${category.materialName}</td><td>${category.specification}</td><td>${category.material}</td><td>${category.remarks}</td><td><a href="${pageContext.request.contextPath}/ToEditMaterialCategoryServlet?ID=${category.materialCode}">修改</a><a href="${pageContext.request.contextPath}/DeleteMaterialCategoryServlet?id=${category.materialCode}">删除</a></td></tr></c:forEach></table><button onclick="addMaterialCategory()">添加物料分类</button><button onclick="window.location.href='${pageContext.request.contextPath}/index.jsp'">返回首页</button>
</div>
</body>
</html>
updateMaterialCategory.jsp
点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %><!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>修改物料分类信息</title><style>body {font-family: Arial, sans-serif;margin: 20px;}.container {max-width: 600px;margin: auto;padding: 20px;border: 1px solid #ccc;border-radius: 5px;}h2 {text-align: center;}form {display: flex;flex-direction: column;}label {margin-top: 10px;}input[type="text"],textarea {padding: 8px;margin-top: 5px;border: 1px solid #ccc;border-radius: 3px;}input[type="submit"] {margin-top: 15px;padding: 10px;background-color: #4CAF50;color: white;border: none;border-radius: 3px;cursor: pointer;}input[type="submit"]:hover {background-color: #45a049;}</style>
</head>
<body>
<div class="container"><h2>修改物料分类信息</h2><form action="${pageContext.request.contextPath}/updateMaterialCategoryServlet" method="post"><input type="hidden" name="materialCode" value="${materialCategory.materialCode}"><label for="materialName">物料名称:</label><input type="text" id="materialName" name="materialName" value="${materialCategory.materialName}" required><label for="specification">规格:</label><input type="text" id="specification" name="specification" value="${materialCategory.specification}"><label for="material">物料类型:</label><input type="text" id="material" name="material" value="${materialCategory.material}"><label for="remarks">备注:</label><textarea id="remarks" name="remarks" rows="4">${materialCategory.remarks}</textarea><input type="submit" value="更新物料分类"></form>
</div>
</body>
</html>
updateWarehouse.jsp
点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %><!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><title>修改仓库信息</title><style>body {font-family: Arial, sans-serif;margin: 20px;}.container {max-width: 600px;margin: auto;padding: 20px;border: 1px solid #ccc;border-radius: 5px;}h2 {text-align: center;}form {display: flex;flex-direction: column;}label {margin-top: 10px;}input[type="text"],input[type="tel"],input[type="number"] {padding: 8px;margin-top: 5px;border: 1px solid #ccc;border-radius: 3px;}input[type="submit"] {margin-top: 15px;padding: 10px;background-color: #4CAF50;color: white;border: none;border-radius: 3px;cursor: pointer;}input[type="submit"]:hover {background-color: #45a049;}</style>
</head>
<body>
<div class="container"><h2>修改仓库信息</h2><form action="${pageContext.request.contextPath}/updateWarehouseServlet" method="post"><input type="hidden" name="warehouseCode" value="${warehouse.warehouseCode}"><label for="warehouseName">仓库名称:</label><input type="text" id="warehouseName" name="warehouseName" value="${warehouse.warehouseName}" required><label for="location">仓库地址:</label><input type="text" id="location" name="location" value="${warehouse.location}"><label for="capacity">仓库容量(小数,例如:1000.50):</label><input type="number" id="capacity" name="capacity" value="${warehouse.capacity}" step="0.01"><label for="contactPerson">联系人:</label><input type="text" id="contactPerson" name="contactPerson" value="${warehouse.contactPerson}"><label for="contactPhone">联系电话:</label><input type="tel" id="contactPhone" name="contactPhone" value="${warehouse.contactPhone}"><input type="submit" value="更新仓库信息"></form>
</div>
</body>
</html>
warehouse.jsp
点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %><!DOCTYPE html>
<html lang="zh-CN">
<head><meta charset="UTF-8"><title>仓库信息打印</title><script>function addHouse() {window.location.href = "addWarehouse.jsp";}</script><style>body {font-family: Arial, sans-serif;margin: 20px;}.container {max-width: 800px;margin: auto;padding: 20px;border: 1px solid #ccc;border-radius: 5px;}h2 {text-align: center;}table {width: 100%;border-collapse: collapse;margin-top: 20px;}th, td {border: 1px solid #ddd;padding: 8px;text-align: center;}th {background-color: #f2f2f2;}</style>
</head>
<body>
<div class="container"><h2>仓库信息打印</h2><hr><table><tr><th>序号</th><th>仓库编码</th><th>仓库名称</th><th>仓库地址</th><th>仓库容量</th><th>联系人</th><th>联系电话</th><th>操作</th></tr><c:forEach items="${warehouseList}" var="warehouse" varStatus="status"><tr><td>${status.count}</td><td>${warehouse.warehouseCode}</td><td>${warehouse.warehouseName}</td><td>${warehouse.location}</td><td>${warehouse.capacity}</td><td>${warehouse.contactPerson}</td><td>${warehouse.contactPhone}</td><td><a href="${pageContext.request.contextPath}/ToFixWarehouseServlet?ID=${warehouse.getWarehouseCode()}">修改</a><a href="${pageContext.request.contextPath}/DeleteWarehouseServlet?id=${warehouse.getWarehouseCode()}">删除</a></td></tr></c:forEach></table><button onclick="addHouse()">添加仓库</button><button onclick="window.location.href='${pageContext.request.contextPath}/index.jsp'">返回首页</button>
</div>
</body>
</html>
七、总结设计 web.xml
点击查看代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"><welcome-file-list><welcome-file>login.html</welcome-file></welcome-file-list>
</web-app>
mybatis-config.xml
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configurationPUBLIC "-//mybatis.org//DTD Config 3.0//EN""http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration><typeAliases>
<!--        记得修改名称--><package name="com.QixunQiu.pojo"/></typeAliases><environments default="development"><environment id="development"><transactionManager type="JDBC"/><dataSource type="POOLED"><property name="driver" value="com.mysql.cj.jdbc.Driver"/>
<!--                数据库名称--><property name="url" value="jdbc:mysql:///cang?useSSL=false&amp;serverTimezone=Hongkong&amp;characterEncoding=utf-8&amp;autoReconnect=true&amp;userServerPreStmts=true"/><property name="username" value="root"/><property name="password" value="1234"/></dataSource></environment></environments><mappers><!--扫描mapper--><package name="com.QixunQiu.mapper"/></mappers>
</configuration>
SqlSessionFactoryUtils
点击查看代码
package com.QixunQiu.util;import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;import java.io.IOException;
import java.io.InputStream;public class SqlSessionFactoryUtils {private static SqlSessionFactory sqlSessionFactory;static {//静态代码块会随着类的加载而自动执行,且执行一次try {String resource = "mybatis-config.xml";InputStream inputStream = Resources.getResourceAsStream(resource);sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);} catch (IOException e) {throw new RuntimeException(e);}}public static SqlSessionFactory getSqlSessionFactory() {return sqlSessionFactory;}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/888563.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

空气流量和空气压力参数解耦系统simulink建模与仿真

1.课题概述空气流量和空气压力参数解耦系统simulink建模与仿真,在许多系统中,空气流量(Q)和压力(P)之间存在耦合关系,这意味着改变一个参数会影响到另一个参数。通过解耦系统解决这种问题,从而提高系统的控制稳定性。2.系统仿真结果 (完整程序运行后无水印)3.核心程序…

【库】Coravel Cache缓存

Coravel 通过使高级应用程序功能(如任务/作业调度、排队、缓存、邮件(以及更多!))易于访问且易于使用,帮助开发人员快速启动并运行 .NET 应用程序。具有简单、富有表现力和直接的语法。Coravel非常简单,通过Rember来保存缓存数据,同时可以设定缓存的时长,然后通过Get来…

4.优化器 - 模型评估

优化器 - optimizer优化器就是在深度学习反向传播过程中,指引损失函数(目标函数)的各个参数往正确的方向更新合适的大小,使得更新后的各个参数损失函数(目标函数)值不断逼近全局最小优化器不计算梯度,他只是梯度的更新者,它决定了以什么样的形式更新参数如果损失函数是…

【软件开发】CMake学习笔记

【软件开发】CMake 学习笔记 CMake 是什么? 是构建系统(如 Visual Studio)的文件(如 .vcxproj .sln)的创建器,具体要生成的构建系统可以通过 CMakePresets 文件中的 generator 指定。 构建系统一般不是跨平台的,但 CMake 支持在不同的操作系统上生成不同的构建系统文件,…

Python糖尿病数据分析:深度学习、逻辑回归、K近邻、决策树、随机森林、支持向量机及模型优化训练评估选择

全文链接:https://tecdat.cn/?p=39864 原文出处:拓端数据部落公众号 分析师:Weilong Zhang 本研究旨在利用机器学习和深度学习模型对糖尿病数据进行分析和预测。通过对糖尿病数据集的读取、预处理、特征分析,运用多种机器学习算法如逻辑回归、K近邻、决策树、随机森林、支…

使用MyBatis框架时Mapper传参是否需要使用@Param注解

在使用MyBatis作为Java项目的ORM框架时,在Mapper接口中传递参数需要通过@Param注解指定参数名称,这样才能在Mapper接口对应的xml文件中引用到对应名称的参数。如果不在Mapper接口中明确使用@Param注解时将会报错:找不到指定名称的参数。 追根溯源,这要从MyBatis获取Mapper接…

关于在阿里云服务器上搭建简单的keepalived主备服务器时出现的问题

问题:在进行keepalived主备服务器配置时,仅配置了RID,状态,通讯端口,VRID,优先级,通告报文发送时间,密码认证部分,VIP。在启动服务时,发现两台设备均跳转状态为MASTER。原因:出现这问题的场景是在阿里VPS云服务器网络环境中,因为路由交换层禁用了ARP的广播限制,造…

子串分值

‌输入和初始化‌: 读取字符串 str,并从索引 1 开始存储(C++ 中字符串索引从 0 开始,但这里为了简化计算,从 1 开始)。 n 存储字符串的长度。 数组 l[i] 存储字符 str[i] 上一次出现的位置。 数组 r[i] 存储字符 str[i] 下一次出现的位置。 数组 p 用于临时存储每个字符最…

【专题】2024年新能源汽车市场年度竞争报告汇总PDF洞察(附原数据表)

原文链接: https://tecdat.cn/?p=39740 在当下快速变革的时代,新能源汽车市场正处于关键的发展十字路口。过去几年间,市场经历了一系列深刻的结构性调整,从市场份额的重新分配到消费者行为模式的显著转变,每一个变化都蕴含着巨大的市场信号。深入分析这些变化背后的数据逻…

pikachu靶场搭建教程

详细介绍了pikachu靶场的搭建,并且附有安装包需要的东西phpStudy: 链接: https://pan.baidu.com/s/1fJ-5TNtdDZGUf5FhTm245g 提取码:0278 pikachu-master: Github链接:Github 链接 链接: https://pan.baidu.com/s/1lDdlxNaa3YjhIEj-WWB3qw 提取码:0278打开 phpstudy ,…

2.17周报

一、本周内容总结本周主要进行了蓝桥和天梯的训练,训练了3场蓝桥、2场天梯,剩余时间的就是赛后补题 补题的过程也重新理清了很多知识,包括gcd和lcm的应用,多项式除法的过程等等 对于蓝桥和天梯的赛制,还重新背了下很多算法的板子,包括求最短路的多种方法,不同范围求组合…

来点树链剖分

树链剖分树链剖分学习笔记 引入 给你一棵树,先单点加,再路径求和,你觉得很简单,用树上差分解决了这个问题。 再给你一棵树,先路径加,再单点查询,你觉得很简单,用树上差分解决了这个问题。 又给你一棵树,上述操作都有,而且顺序不分先后,你发现树上差分不能解决这个问…