Web——企业信息文档管理系统

Web文档管理系统

  • 欢迎Web文档管理系统
    • 1.开发技术
    • 2.系统总体设计
    • 3.数据存储方案
    • 4.功能实现
    • 5.运行结果
      • 测试结果与分析
      • 测试
    • 6.核心代码
      • Jsp
      • Java
      • 源代码工程下载

欢迎Web文档管理系统

  • 首先对整体架构进行分析,进而分配组员任务,根据案例解决方案将组员合理划分责任,落实功能实现Deadline。
  • 整体系统的前台,也就是普通的用户模式,在用户界面,用户可以通过登陆界面登录,若没有账户,可以选择注册账户,之后选择登录;登陆后可以查找文档并预览所有文件,之后对需要打印的文件选择打印。
  • 整体系统的后台,也就是管理员模式,在管理员界面,管理员可以通过登陆界面登录,但是管理员无法在登陆选择注册管理员注册,默认admin(admin123)账号可以对包括管理员和用户的全部账号进行管理,对用户权限进行管理,对文档类别进行管理,对文档信息进行管理,对文档附件进行管理。
  • 通过Jsp实现上述功能,并且在浏览器端可以对相应功能进行操作。

1.开发技术

  1. JSP原理:
  • 客户端通过浏览器向服务器发出请求,在该请求中包含了请求的资源的路径,这样当服务器接收到该请求后就可以知道被请求的内容。
  • 服务器根据接收到的客户端的请求来加载相应的JSP文件。
  • Web服务器Tomcat9.1.04中的JSP引擎会将被加载的JSP文件转化为Servlet。
  • JSP引擎将生成的Servlet代码编译成Class文件。服务器Tomcat9.1.04执行这个Class文件,最后服务器将执行结果发送给浏览器进行显示。
  1. 程序开发环境和开发语言
  • 开发环境方面

运行VMware 15.5.0 虚拟机,配置内存4GB,单核4线程
Window 10企业版LTSC x64
JDK 11.0.4 windows-x64
IntelliJ IDEA 2020.1 x64
Mysql 5.1.55
Navicat 10.0.11
Tomcat 9.0.41
Firefox 84.0.1 x64
Google Chrome 87.0.4280.88 x64
Enterprise Architect 12.0.1209

  • 开发语言方面,

基于IntelliJ IDEA强大功能,进行Java,HTML,CSS等编写和调用。团队合作时。
前端页面编写用到HbuilderX等HTML编写工具进行HTML编写和CSS渲染。

2.系统总体设计

Web——企业信息文档管理系统_第1张图片

3.数据存储方案

  • 数据通过Mysql数据库,引擎采用InnoDB
  • 创建“document”库,并建立相对应的表
    Web——企业信息文档管理系统_第2张图片
/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

CREATE DATABASE /*!32312 IF NOT EXISTS*/`document` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `document`;


DROP TABLE IF EXISTS `document_attachment`;
CREATE TABLE `document_attachment`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `path` varchar(255) DEFAULT NULL,
  `size` int(11) DEFAULT NULL,
  `document_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`) 
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `document_category`;
CREATE TABLE `document_category`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`) 
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

DROP TABLE IF EXISTS `document_info`;
CREATE TABLE `document_info`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) DEFAULT NULL,
  `content` varchar(255) DEFAULT NULL,
  `document_category` varchar(255)DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `user_info`;
CREATE TABLE `user_info`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) DEFAULT NULL,
  `password` varchar(255) DEFAULT NULL,
  `user_permissions` varchar(255)DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;


DROP TABLE IF EXISTS `user_permissions`;
CREATE TABLE `user_permissions`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `user_permissions` varchar(255)DEFAULT NULL,
  PRIMARY KEY (`id`) 
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

4.功能实现

  1. 系统注册登录
  • 用户注册登录模块实现用户注册登录功能,企业员工用户登录后,能查看相关文档信息和打印文档信息等;管理员用户登录系统后,能通过后台对系统进行维护和管理,主要包括用户角色管理,文档类别管理和文档信息管理等。
  • 首先会根据用户输入的账号和密码,在LoginServlet中获取对应参数,并进行查表获取用户信息。如果用户信息错误,则返回“用户名或者密码错误”相应提示。如果用户信息正确,则根据用户类型来判断是管理员还是普通用户,从而跳转到不同首页。管理员则跳转到后台管理首页,非管理员则跳转到前台首页。
  1. 文档类别管理
  • 文档类别管理模块实现对文档类别的管理,主要包括文档类别的添加,修改和删除。
  1. 文档信息管理
  • 文档信息管理模块实现对文档信息的管理功能,主要包括对文档进行添加,修改,删除,查看和文档的浏览功能等。
  1. 文档信息查询
  • 文档信息查询模块实现对文档的综合查询功能,主要包括按文档类别查询,按文档标题查询,模糊匹配查询等。
  1. 文档附件管理
  • 文档附件管理模块实现对文档附件的管理功能。主要包括对文件的添加,编辑和删除。

5.运行结果

Web——企业信息文档管理系统_第3张图片
Web——企业信息文档管理系统_第4张图片
Web——企业信息文档管理系统_第5张图片
Web——企业信息文档管理系统_第6张图片
Web——企业信息文档管理系统_第7张图片
Web——企业信息文档管理系统_第8张图片
Web——企业信息文档管理系统_第9张图片
Web——企业信息文档管理系统_第10张图片
Web——企业信息文档管理系统_第11张图片
Web——企业信息文档管理系统_第12张图片
Web——企业信息文档管理系统_第13张图片
Web——企业信息文档管理系统_第14张图片
Web——企业信息文档管理系统_第15张图片
Web——企业信息文档管理系统_第16张图片

测试结果与分析

  • 首先打开IntelliJ IDEA,之后进行Tomcat配置,Jar配置等
  • 环境配置成功后开始debug程序,等待Tomcat显示绿色后,Web exploded显示绿色对号后,进行访问地址:http://localhost:8080/Document_Sys_Web_exploded/front/login.jsp,便可以进入文档管理系统的登陆界面,在界面中可以选择已知的用户或者管理员账号和密码进行登录,如果没有账号,点击“点击注册”超链接进入注册界面进行注册,注册成功后自动跳转至登陆界面进行登录。
  • 用户界面可以查找文件和浏览打印文件。
  • 管理员账号admin(admin123)进行用户信息,用户权限,文档类别,文档信息,文档附件的增删改操作。
  • 整套系统反馈延时低于用户最大等待时间,SQL语句简洁干练,尽可能保证在不提高空间复杂度的条件下降低整体系统的时间复杂度。

测试

在测试中,进行路径覆盖测试:

操作步骤 输入数据 期望结果
点击注册,在用户名后文本框内输入用户名,在密码后文本框内输入密码,点击注册后,跳转到登录界面进行登录 自定义用户名,自定义密码 显示注册成功,并进入用户页面
在用户名后文本框内输入admin,在密码后文本框内输入admin123,进行登录 对应的用户名,对应的密码 登录Admin后台界面
依次点击管理员后台按钮和用户前台按钮 正确用户名和对应密码 操作成功!

6.核心代码

Jsp

  • index
<%@ page import="model.UserInfo" %>
<%@ page import="cn.hutool.core.util.StrUtil" %>
<%@ page import="mapper.DocumentInfoMapper" %>
<%@ page import="model.DocumentInfo" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: GodOuO
  Date: 2020/12/27
  Time: 20:20
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>用户首页</title>
    <style>
        body{
     
            background: url("../images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>
<body style="text-align:center;">
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: #cc0;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*鼠标悬停时背景颜色变橙*/

</style>
<h1>文档管理系统-User</h1>
<div>

    <form action="<%=request.getContextPath()%>/front/index.jsp">
        <%
            UserInfo user = (UserInfo) session.getAttribute("user");
            if (user != null) {
     
                out.write("" + user.getUsername() + "\n" +
                        " + request.getContextPath() + "/logout\">退出登录");
            } else {
     
                out.write(" + request.getContextPath() + "/front/login.jsp\">登录\n" +
                        " /\n" +
                        "  + request.getContextPath() + "/front/register.jsp\">注册");
            }
        %>
        <%
            String name = request.getParameter("name");
            DocumentInfo book = new DocumentInfo();
            book.setName(name);
            List<DocumentInfo> search = DocumentInfoMapper.search(book);
        %>
        <span style="padding-right: 50px"></span>
        <input type="text" placeholder="请输入名称..." value="" name="name">
        <button type="submit">搜索</button>
    </form>
</div>
<hr>
<br>
<div style="text-align: center;">
    <table border="1" style="margin: auto;">
        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>内容</th>
            <th>文档类别</th>
            <th>操作</th>
        </tr>
        <c:forEach items="<%=search%>" var="b">
            <tr>
                <td>${
     b.id}</td>
                <td>${
     b.name}</td>
                <td>${
     b.content}</td>
                <td>合同</td>
                <td>
                    <button >打印</button>
                </td>
            </tr>
        </c:forEach>
    </table>
</div>
</body>
</html>

  • login
<%--
  Created by IntelliJ IDEA.
  User: GodOuO
  Date: 2020/12/25
  Time: 20:38
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>登录</title>
    <style>
        body{
     
            background: url("../images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>
<body style="text-align:center;">
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    tr.td{
     
        width: 20%;
        text-align: right;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        padding-right: 10px;
        margin-top: 10px;
        color: #888
    }
    a:visited{
     
        text-decoration:none;   //去除下划线
        background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*鼠标悬停时背景颜色变橙*/

    .div0{
     
        position:absolute;
           /*定位方式绝对定位absolute*/
        top:50%;
        left:50%;
        /*顶和高同时设置50%实现的是同时水平垂直居中效果*/
        transform:translate(-50%,-50%);
        /*实现块元素百分比下居中*/
        width:450px;
        padding:50px;
        background: rgba(255,255,255,.3);
        /*背景颜色为白色,透明度为0.8*/
        box-sizing:border-box;
        /*box-sizing设置盒子模型的解析模式为怪异盒模型,
24     将border和padding划归到width范围内*/
        box-shadow: 0px 15px 25px rgba(0,0,0,0.5);
        /*边框阴影  水平阴影0 垂直阴影15px 模糊25px 颜色黑色透明度0.5*/
        border-radius:15px;
        /*边框圆角,四个角均为15px*/
    }
    .div2{
     
        margin-left: 500px;
    }
</style>
<h1>文档管理系统登录</h1>
<br>
<div class="div0">
    <form action="<%=request.getContextPath()%>/login" method="post">
            <div class="div1">
                用户名:
                <input type="text" placeholder="用户名" name="username" value="">
            </div>
            <div class="div1">&emsp;码:
                <input type="password" placeholder="密码" name="password" value="">
            </div>
        <br>
                    <button type="submit">登录</button>
                    <button type="reset">重置</button>
         <br>
                没有账户?<a href="<%=request.getContextPath()%>/front/register.jsp">点击注册</a>
             <span style="color: red">${
     sessionScope.error}</span></td>

    </form>
</div>
</body>
</html>
<%
    session.removeAttribute("error");
%>
  • register
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
    <style>
        body{
     
            background: url("../images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>
<body style="text-align:center;">
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    tr.td{
     
        width: 20%;
        text-align: right;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        padding-right: 10px;
        margin-top: 10px;
        color: #888
    }
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*鼠标悬停时背景颜色变橙*/

</style>
<h1>文档管理系统注册账号</h1>

<br>
<div>
    <form action="<%=request.getContextPath()%>/register" method="post">
        <table style="margin: auto">
            <tr>
                <td>用户名:</td>
                <td><input type="text" placeholder="用户名" name="username" value=""></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" placeholder="密码" name="password" value=""></td>
            </tr>
            <tr>
                <td>确认:</td>
                <td><input type="password" placeholder="密码" value=""></td>
            </tr>
            <tr>
                <td>
                    <button type="submit">注册</button>
                </td>
                <td>
                    <button type="reset">重置</button>
                </td>
            </tr>
            <tr>
                <td></td>
                <td>已有账号?<a href="<%=request.getContextPath()%>/front/login.jsp">点击登录</a></td>
            </tr>
            <tr>
                <td><span style="color: red">${
     sessionScope.error}</span></td>
            </tr>
        </table>
    </form>
</div>
</body>
</html>
<%
session.removeAttribute("error");
%>

  • DocumentAttachment
<%@ page import="cn.hutool.core.util.StrUtil" %>
<%@ page import="mapper.DocumentAttachmentMapper" %>
<%@ page import="model.DocumentAttachment" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>DocumentAttachment</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>

<body style="text-align:center;">
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*标悬停时背景颜色变橙*/

</style>
<h1>文档附件管理</h1>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/DocumentAttachmentAdd.jsp">
        <button>添加</button>
    </a>
</div>
<hr>
<br>
<div style="text-align: center;">
    <table style="margin: auto;">
        <tr>
            <td>
                <jsp:include page="spider.jsp"/>
            </td>
            <td><span style="padding-right: 30px"></span></td>
            <td>
                <table border="1" style="margin: auto;">
                    <tr>
<th>ID</th>
<th>名称</th>
<th>路径</th>
<th>大小</th>
<th>文档ID</th>
                        <th>操作</th>
                    </tr>
                    <%
                        for (DocumentAttachment temp : DocumentAttachmentMapper.list()) {
     
                            out.write("\n" +
                                    "                        " + temp.getId() + "\n" +
                                    "                        " + temp.getName() + "\n" +
                                    "                        " + temp.getPath() + "\n" +
                                    "                        " + temp.getSize() + "\n" +
                                    "                        " + temp.getDocumentId() + "\n" +
                                    "                        \n" +
                                    "                            + request.getContextPath() + "/documentAttachment?method=getById&id=" + temp.getId() + ">\n" +
                                    "                            + request.getContextPath() + "/documentAttachment?method=deleteById&id=" + temp.getId() + ">\n" +
                                    "                        \n" +
                                    "                    ");
                        }
                    %>
                </table>
            </td>
        </tr>
    </table>
</div>
</body>
</html>

  • DocumentAttachmentAdd

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>DocumentAttachmentAdd</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>
<body style="text-align:center;">
<h1>文档附件添加</h1>
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*鼠标悬停时背景颜色变橙*/

</style>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/index.jsp">
        <button>返回</button>
    </a>
</div>
<hr>
<br>
<c:if test="${sessionScope.documentAttachment==null}">
<form action="<%=request.getContextPath()%>/documentAttachment?method=addBean" method="post">
    </c:if>
    <c:if test="${sessionScope.documentAttachment!=null}">
    <form action="<%=request.getContextPath()%>/documentAttachment?method=updateById" method="post">
        </c:if>    <table style="margin: auto">            <tr>
                <td>ID</td>
                <td><input type="text" prefix="ID" name="id" value="${sessionScope.documentAttachment.id}"></td>
            </tr>
            <tr>
                <td>名称:</td>
                <td><input type="text" prefix="名称" name="name" value="${sessionScope.documentAttachment.name}"></td>
            </tr>
            <tr>
                <td>路径:</td>
                <td><input type="text" prefix="路径" name="path" value="${sessionScope.documentAttachment.path}"></td>
            </tr>
            <tr>
                <td>大小:</td>
                <td><input type="text" prefix="大小" name="size" value="${sessionScope.documentAttachment.size}"></td>
            </tr>
            <tr>
                <td>文档ID</td>
                <td><input type="text" prefix="文档ID" name="documentId" value="${sessionScope.documentAttachment.documentId}"></td>
            </tr>
            <tr>
                <td>
                    <button type="submit">添加</button>
                </td>
                <td>
                    <button type="reset">重置</button>
                </td>
            </tr>
    </table>
</form>
</body>
</html>
<%
session.removeAttribute("documentAttachment");
%>
  • DocumentCategory
<%@ page import="cn.hutool.core.util.StrUtil" %>
<%@ page import="mapper.DocumentCategoryMapper" %>
<%@ page import="model.DocumentCategory" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>DocumentCategory</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>

<body style="text-align:center;">
<h1>文档类别管理</h1>
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*鼠标悬停时背景颜色变橙*/

</style>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/DocumentCategoryAdd.jsp">
        <button>添加</button>
    </a>
</div>
<hr>
<br>
<div style="text-align: center;">
    <table style="margin: auto;">
        <tr>
            <td>
                <jsp:include page="spider.jsp"/>
            </td>
            <td><span style="padding-right: 30px"></span></td>
            <td>
                <table border="1" style="margin: auto;">
                    <tr>
<th>ID</th>
<th>类别名称</th>
                        <th>操作</th>
                    </tr>
                    <%
                        for (DocumentCategory temp : DocumentCategoryMapper.list()) {
     
                            out.write("\n" +
                                    "                        " + temp.getId() + "\n" +
                                    "                        " + temp.getName() + "\n" +
                                    "                        \n" +
                                    "                            + request.getContextPath() + "/documentCategory?method=getById&id=" + temp.getId() + ">\n" +
                                    "                            + request.getContextPath() + "/documentCategory?method=deleteById&id=" + temp.getId() + ">\n" +
                                    "                        \n" +
                                    "                    ");
                        }
                    %>
                </table>
            </td>
        </tr>
    </table>
</div>
</body>
</html>

  • DocumentCategoryAdd

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>DocumentCategoryAdd</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>
<body style="text-align:center;">
<h1>文档类别添加</h1>
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*鼠标悬停时背景颜色变橙*/

</style>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/index.jsp">
        <button>返回</button>
    </a>
</div>
<hr>
<br>
<c:if test="${sessionScope.documentCategory==null}">
<form action="<%=request.getContextPath()%>/documentCategory?method=addBean" method="post">
    </c:if>
    <c:if test="${sessionScope.documentCategory!=null}">
    <form action="<%=request.getContextPath()%>/documentCategory?method=updateById" method="post">
        </c:if>    <table style="margin: auto">            <tr>
                <td>ID</td>
                <td><input type="text" prefix="ID" name="id" value="${sessionScope.documentCategory.id}"></td>
            </tr>
            <tr>
                <td>类别名称:</td>
                <td><input type="text" prefix="类别名称" name="name" value="${sessionScope.documentCategory.name}"></td>
            </tr>
            <tr>
                <td>
                    <button type="submit">添加</button>
                </td>
                <td>
                    <button type="reset">重置</button>
                </td>
            </tr>
    </table>
</form>
</body>
</html>
<%
session.removeAttribute("documentCategory");
%>
  • DocumentInfo
<%@ page import="cn.hutool.core.util.StrUtil" %>
<%@ page import="mapper.DocumentInfoMapper" %>
<%@ page import="model.DocumentInfo" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>DocumentInfo</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>

<body style="text-align:center;">
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: lightsteelblue;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*鼠标悬停时背景颜色变橙*/

</style>
<h1>文档信息管理</h1>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/DocumentInfoAdd.jsp">
        <button>添加</button>
    </a>
</div>
<hr>
<br>
<div style="text-align: center;">
    <table style="margin: auto;">
        <tr>
            <td>
                <jsp:include page="spider.jsp"/>
            </td>
            <td><span style="padding-right: 30px"></span></td>
            <td>
                <table border="1" style="margin: auto;">
                    <tr>
<th>ID</th>
<th>名称</th>
<th>内容</th>
<th>文档类别</th>
                        <th>操作</th>
                    </tr>
                    <%
                        for (DocumentInfo temp : DocumentInfoMapper.list()) {
     
                            out.write("\n" +
                                    "                        " + temp.getId() + "\n" +
                                    "                        " + temp.getName() + "\n" +
                                    "                        " + temp.getContent() + "\n" +
                                    "                        " + temp.getDocumentCategory() + "\n" +
                                    "                        \n" +
                                    "                            + request.getContextPath() + "/documentInfo?method=getById&id=" + temp.getId() + ">\n" +
                                    "                            + request.getContextPath() + "/documentInfo?method=deleteById&id=" + temp.getId() + ">\n" +
                                    "                        \n" +
                                    "                    ");
                        }
                    %>
                </table>
            </td>
        </tr>
    </table>
</div>
</body>
</html>

  • DocumentInfoAdd

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>DocumentInfoAdd</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>
<body style="text-align:center;">
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: #cc0;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background: cornflowerblue;
    }  /*鼠标悬停时背景颜色变橙*/

</style>
<h1>文档信息添加</h1>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/index.jsp">
        <button>返回</button>
    </a>
</div>
<hr>
<br>
<c:if test="${sessionScope.documentInfo==null}">
<form action="<%=request.getContextPath()%>/documentInfo?method=addBean" method="post">
    </c:if>
    <c:if test="${sessionScope.documentInfo!=null}">
    <form action="<%=request.getContextPath()%>/documentInfo?method=updateById" method="post">
        </c:if>    <table style="margin: auto">            <tr>
                <td>ID</td>
                <td><input type="text" prefix="ID" name="id" value="${sessionScope.documentInfo.id}"></td>
            </tr>
            <tr>
                <td>名称:</td>
                <td><input type="text" prefix="名称" name="name" value="${sessionScope.documentInfo.name}"></td>
            </tr>
            <tr>
                <td>内容:</td>
                <td><input type="text" prefix="内容" name="content" value="${sessionScope.documentInfo.content}"></td>
            </tr>
            <tr>
                <td>文档类别:</td>
                <td><input type="text" prefix="文档类别" name="documentCategory" value="${sessionScope.documentInfo.documentCategory}"></td>
            </tr>
            <tr>
                <td>
                    <button type="submit">添加</button>
                </td>
                <td>
                    <button type="reset">重置</button>
                </td>
            </tr>
    </table>
</form>
</body>
</html>
<%
session.removeAttribute("documentInfo");
%>
  • index

<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<jsp:include page="UserInfo.jsp"/>

  • spider
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <style>
        font{
     
            color: black;
        }
    </style>
</head>
<body>
<li><a href="<%=request.getContextPath()%>/UserInfo.jsp"><font>用户信息管理</font></a></li>
<li><a href="<%=request.getContextPath()%>/UserPermissions.jsp"><font>用户权限管理</font></a></li>
<li><a href="<%=request.getContextPath()%>/DocumentCategory.jsp"><font>文档类别管理</font></a></li>
<li><a href="<%=request.getContextPath()%>/DocumentInfo.jsp"><font>文档信息管理</font></a></li>
<li><a href="<%=request.getContextPath()%>/DocumentAttachment.jsp"><font>文档附件管理</font></a></li>
</body>
</html>


  • UserInfo
<%@ page import="cn.hutool.core.util.StrUtil" %>
<%@ page import="mapper.UserInfoMapper" %>
<%@ page import="model.UserInfo" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>UserInfo</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>

<body style="text-align:center;">
<style type="text/css">

    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5f5a4b, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        background-clip: padding-box; /*背景被裁剪到内边距框*/
        position:relative;
        height: 25px;
        line-height: 25px;
        text-align: center;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  /*鼠标悬停时背景颜色变橙*/

</style>
<h1>用户信息管理</h1>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/UserInfoAdd.jsp">
        <button>添加</button>
    </a>
</div>
<hr>
<br>
<div style="text-align: center;">
    <table style="margin: auto;">
        <tr>
            <td>
                <jsp:include page="spider.jsp"/>
            </td>
            <td><span style="padding-right: 30px"></span></td>
            <td>
                <table border="1" style="margin: auto;">
                    <tr>

                        <th>ID</th>
                        <th>姓名</th>
                        <th>密码</th>
                        <th>用户权限</th>
                            <th>操作</th>
                    </tr>
                    <%
                        for (UserInfo temp : UserInfoMapper.list()) {
     
                            out.write("\n" +
                                    "                        " + temp.getId() + "\n" +
                                    "                        " + temp.getUsername() + "\n" +
                                    "                        " + temp.getPassword() + "\n" +
                                    "                        " + temp.getUserPermissions() + "\n" +
                                    "                        \n" +
                                    "                            + request.getContextPath() + "/userInfo?method=getById&id=" + temp.getId() + ">\n" +
                                    "                            + request.getContextPath() + "/userInfo?method=deleteById&id=" + temp.getId() + ">\n" +
                                    "                        \n" +
                                    "                    ");
                        }
                    %>
                </table>
            </td>
        </tr>
    </table>
</div>
</body>
</html>
  • UserInfoAdd

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>UserInfoAdd</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>
<body style="text-align:center;">
<h1>用户信息添加</h1>
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  //鼠标悬停时背景颜色变橙

</style>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/index.jsp">
        <button>返回</button>
    </a>
</div>
<hr>
<br>
<c:if test="${sessionScope.userInfo==null}">
<form action="<%=request.getContextPath()%>/userInfo?method=addBean" method="post">
    </c:if>
    <c:if test="${sessionScope.userInfo!=null}">
    <form action="<%=request.getContextPath()%>/userInfo?method=updateById" method="post">
        </c:if>    <table style="margin: auto">            <tr>
                <td>ID</td>
                <td><input type="text" prefix="ID" name="id" value="${sessionScope.userInfo.id}"></td>
            </tr>
            <tr>
                <td>姓名:</td>
                <td><input type="text" prefix="姓名" name="username" value="${sessionScope.userInfo.username}"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="text" prefix="密码" name="password" value="${sessionScope.userInfo.password}"></td>
            </tr>
            <tr>
                <td>用户权限:</td>
                <td><input type="text" prefix="用户权限" name="userPermissions" value="${sessionScope.userInfo.userPermissions}"></td>
            </tr>
            <tr>
                <td>
                    <button type="submit">添加</button>
                </td>
                <td>
                    <button type="reset">重置</button>
                </td>
            </tr>
    </table>
</form>
</body>
</html>
<%
session.removeAttribute("userInfo");
%>
  • UserPermissions
<%@ page import="cn.hutool.core.util.StrUtil" %>
<%@ page import="mapper.UserPermissionsMapper" %>
<%@ page import="model.UserPermissions" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>UserPermissions</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>

<body style="text-align:center;">
<h1>用户权限管理</h1>
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        background-clip: padding-box; /*背景被裁剪到内边距框*/
        position:relative;
        height: 25px;
        line-height: 25px;
        text-align: center;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  //鼠标悬停时背景颜色变橙

</style>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/UserPermissionsAdd.jsp">
        <button>添加</button>
    </a>
</div>
<hr>
<br>
<div style="text-align: center;">
    <table style="margin: auto;">
        <tr>
            <td>
                <jsp:include page="spider.jsp"/>
            </td>
            <td><span style="padding-right: 30px"></span></td>
            <td>
                <table border="1" style="margin: auto;">
                    <tr>
<th>ID</th>
<th>用户权限</th>
                        <th>操作</th>
                    </tr>
                    <%
                        for (UserPermissions temp : UserPermissionsMapper.list()) {
     
                            out.write("\n" +
                                    "                        " + temp.getId() + "\n" +
                                    "                        " + temp.getUserPermissions() + "\n" +
                                    "                        \n" +
                                    "                            + request.getContextPath() + "/userPermissions?method=getById&id=" + temp.getId() + ">\n" +
                                    "                            + request.getContextPath() + "/userPermissions?method=deleteById&id=" + temp.getId() + ">\n" +
                                    "                        \n" +
                                    "                    ");
                        }
                    %>
                </table>
            </td>
        </tr>
    </table>
</div>
</body>
</html>

  • UserPermissionsAdd

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>UserPermissionsAdd</title>
    <style>
        body{
     
            background: url("images/4.jpg");
            background-size: 100%;
            background-size: cover;
        }
    </style>
</head>
<body style="text-align:center;">
<style type="text/css">
    h1{
     
        background: #2B6695;
        border-radius: 6px 6px 6px 6px;
        box-shadow: 0 0 0 1px #5F5A4B, 1px 1px 6px 1px rgba(10, 10, 0, 0.5);
        color: #FFFFFF;
        font-family:"微软雅黑", "宋体", "黑体", Arial;
        font-size: 18px;
        font-weight: bold;
        height: 25px;
        line-height: 25px;
        margin: 18px 0 !important;
        padding: 8px 0 5px 5px;
        text-shadow: 2px 2px 3px #222222;
    }
    button{
     
        background:-webkit-linear-gradient(top ,rgb(169,169,169),rgb(34,102,149) 50%,rgb(34,102,140) 50%,rgb(128,128,128) 100%);
        display:inline-block;
        border:rgb(169,169, 187) solid 1px;
        box-shadow:inset rgba(255,255,255,1.0) 0px 0px 2px 0px;
        border-radius:8px;
        outline:none;
        width:45px;
        height:20px;
        cursor:pointer;
        color:#ffffff;
        font-size:10px;
    }
    table {
     
        width: 90%;
        background: #ccc;
        margin: 10px auto;
        border-collapse: collapse;/*border-collapse:collapse合并内外边距(去除表格单元格默认的2个像素内外边距*/
    }
    th,td {
     
        height: 25px;
        line-height: 25px;
        text-align: center;
        border: 1px solid #ccc;
    }
    th {
     
        background: #eee;
        font-weight: normal;
    }
    tr {
     
        background: #fff;
    }
    tr:hover {
     
        background: cornflowerblue;
    }
    td a {
     
        color: #06f;
        text-decoration: none;
    }
    td a:hover {
     
        color: #06f;
        text-decoration: underline;}
    a:visited{
     
        text-decoration:none;   //去除下划线
    background-color: purple;
        color:gray;
    }
    a:hover{
     
        background-color: orange;
    }  //鼠标悬停时背景颜色变橙

</style>
<h1>用户权限添加</h1>
<div>
    <span>${
     sessionScope.user.username}</span>
    <span><a href="<%=request.getContextPath()%>/logout">退出登录</a></span>
    <span style="padding-right: 50px"></span>
    <a href="<%=request.getContextPath()%>/index.jsp">
        <button>返回</button>
    </a>
</div>
<hr>
<br>
<c:if test="${sessionScope.userPermissions==null}">
<form action="<%=request.getContextPath()%>/userPermissions?method=addBean" method="post">
    </c:if>
    <c:if test="${sessionScope.userPermissions!=null}">
    <form action="<%=request.getContextPath()%>/userPermissions?method=updateById" method="post">
        </c:if>    <table style="margin: auto">            <tr>
                <td>ID</td>
                <td><input type="text" prefix="ID" name="id" value="${sessionScope.userPermissions.id}"></td>
            </tr>
            <tr>
                <td>用户权限:</td>
                <td><input type="text" prefix="用户权限" name="userPermissions" value="${sessionScope.userPermissions.userPermissions}"></td>
            </tr>
            <tr>
                <td>
                    <button type="submit">添加</button>
                </td>
                <td>
                    <button type="reset">重置</button>
                </td>
            </tr>
    </table>
</form>
</body>
</html>
<%
session.removeAttribute("userPermissions");
%>

Java

  • JDBCUtils
package utils;


import java.io.IOException;
import java.io.InputStream;
import java.sql.*;
import java.util.Properties;

/**
 * JDBC 工具类
 */
public class JDBCUtils {
     
    private static String url;
    private static String user;
    private static String password;
    private static String driver;

    /**
     * 文件读取,只会执行一次,使用静态代码块
     */
    static {
     
        //读取文件,获取值
        try {
     
            //1.创建Properties集合类
            Properties pro = new Properties();
            //获取src路径下的文件--->ClassLoader类加载器
            ClassLoader classLoader = JDBCUtils.class.getClassLoader();
            InputStream resourceAsStream = classLoader.getResourceAsStream("jdbc.properties");
            //2.加载文件
            pro.load(resourceAsStream);
            //3获取数据
            url = pro.getProperty("dataSource.jdbcUrl");
            user = pro.getProperty("dataSource.username");
            password = pro.getProperty("dataSource.password");
            driver = pro.getProperty("dataSource.driverClass");
            //4.注册驱动
            Class.forName(driver);
            resourceAsStream.close();
        } catch (IOException e) {
     
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
     
            e.printStackTrace();
        }
    }

    /**
     * 获取连接
     *
     * @return 连接对象
     */
    public static Connection getConnection() throws SQLException {
     
        Connection conn = DriverManager.getConnection(url, user, password);
        return conn;
    }

    /**
     * 释放资源
     */
    public static void close(ResultSet rs, Statement st, Connection conn) {
     
        if (rs != null) {
     
            try {
     
                rs.close();
            } catch (SQLException e) {
     
                e.printStackTrace();
            }
        }
        if (st != null) {
     
            try {
     
                st.close();
            } catch (SQLException e) {
     
                e.printStackTrace();
            }
        }
        if (conn != null) {
     
            try {
     
                conn.close();
            } catch (SQLException e) {
     
                e.printStackTrace();
            }
        }
    }

    public static void close(Statement st, Connection conn) {
     
        if (st != null) {
     
            try {
     
                st.close();
            } catch (SQLException e) {
     
                e.printStackTrace();
            }
        }
        if (conn != null) {
     
            try {
     
                conn.close();
            } catch (SQLException e) {
     
                e.printStackTrace();
            }
        }
    }
}
dataSource.driverClass=com.mysql.jdbc.Driver
dataSource.jdbcUrl=jdbc:mysql://localhost:3306/document?useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
dataSource.username=root
dataSource.password=***
  • EncodingFilter
package filter;

import javax.servlet.*;
import java.io.IOException;

public class EncodingFilter implements Filter {
     

    private String charEncoding = null;

    public EncodingFilter() {
     
    }

    /**
     * @see Filter#init(FilterConfig)
     */
    public void init(FilterConfig fConfig) throws ServletException {
     
        charEncoding = fConfig.getInitParameter("charEncoding");
        if (charEncoding == null || charEncoding.equals("null")) {
     
            throw new ServletException("EncodingFilter中的编码设置为空");
        }
    }

    /**
     * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
     */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
     
        // 将设置的编码与请求的编码进行比较,若不同,则将请求的编码设置为设置的编码
        if (!charEncoding.equals(request.getCharacterEncoding())) {
     
            request.setCharacterEncoding(charEncoding);
        }
        // 将相应的编码设置为设置的编码
        response.setCharacterEncoding(charEncoding);
        chain.doFilter(request, response);

    }

    /**
     * @see Filter#destroy()
     */
    public void destroy() {
     
        // TODO Auto-generated method stub
    }
}
  • DocumentAttachmentMapper
package mapper;

import org.springframework.jdbc.mapper.MapperUtils;
import model.DocumentAttachment;
import java.util.List;
import utils.JDBCUtils;
import java.util.ArrayList;
import java.sql.*;

public class DocumentAttachmentMapper {
     
    public static List<DocumentAttachment> list() throws Exception{
     
       return  list(null);
    }

    public static List<DocumentAttachment> list(DocumentAttachment DocumentAttachment)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from document_attachment";
        sql += MapperUtils.getEqualCondition(DocumentAttachment);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (Exception throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<DocumentAttachment> list = new ArrayList<>();
            while (resultSet.next()) {
     
                DocumentAttachment temp = new DocumentAttachment();
                temp.setId(resultSet.getInt("id"));
                temp.setName(resultSet.getString("name"));
                temp.setPath(resultSet.getString("path"));
                temp.setSize(resultSet.getInt("size"));
                temp.setDocumentId(resultSet.getInt("document_id"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static List<DocumentAttachment> search(DocumentAttachment documentAttachment)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from document_attachment";
        sql += MapperUtils.getLikeCondition(documentAttachment);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<DocumentAttachment> list = new ArrayList<>();
            while (resultSet.next()) {
     
                DocumentAttachment temp = new DocumentAttachment();
                temp.setId(resultSet.getInt("id"));
                temp.setName(resultSet.getString("name"));
                temp.setPath(resultSet.getString("path"));
                temp.setSize(resultSet.getInt("size"));
                temp.setDocumentId(resultSet.getInt("document_id"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }


    public static boolean add(DocumentAttachment documentAttachment) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "insert into document_attachment(id,name,path,size,document_id) values (NULL,?,?,?,?)";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, documentAttachment.getName());
            preparedStatement.setString(2, documentAttachment.getPath());
            preparedStatement.setInt(3, documentAttachment.getSize());
            preparedStatement.setInt(4, documentAttachment.getDocumentId());
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static boolean deleteById(Integer id)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "delete from document_attachment where id=" + id;
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static int updateById(Integer id, DocumentAttachment documentAttachment) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "update document_attachment set ";
        sql += MapperUtils.getUpdateCondition(documentAttachment);
        sql += " where id = '" + id + "'";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.executeUpdate();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
}
  • DocumentCategoryMapper
package mapper;

import org.springframework.jdbc.mapper.MapperUtils;
import model.DocumentCategory;
import java.util.List;
import utils.JDBCUtils;
import java.util.ArrayList;
import java.sql.*;

public class DocumentCategoryMapper {
     
    public static List<DocumentCategory> list() throws Exception{
     
       return  list(null);
    }

    public static List<DocumentCategory> list(DocumentCategory DocumentCategory)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from document_category";
        sql += MapperUtils.getEqualCondition(DocumentCategory);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (Exception throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<DocumentCategory> list = new ArrayList<>();
            while (resultSet.next()) {
     
                DocumentCategory temp = new DocumentCategory();
                temp.setId(resultSet.getInt("id"));
                temp.setName(resultSet.getString("name"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static List<DocumentCategory> search(DocumentCategory documentCategory)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from document_category";
        sql += MapperUtils.getLikeCondition(documentCategory);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<DocumentCategory> list = new ArrayList<>();
            while (resultSet.next()) {
     
                DocumentCategory temp = new DocumentCategory();
                temp.setId(resultSet.getInt("id"));
                temp.setName(resultSet.getString("name"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }


    public static boolean add(DocumentCategory documentCategory) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "insert into document_category(id,name) values (NULL,?)";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, documentCategory.getName());
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static boolean deleteById(Integer id)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "delete from document_category where id=" + id;
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static int updateById(Integer id, DocumentCategory documentCategory) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "update document_category set ";
        sql += MapperUtils.getUpdateCondition(documentCategory);
        sql += " where id = '" + id + "'";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.executeUpdate();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
}
  • DocumentInfoMapper
package mapper;

import org.springframework.jdbc.mapper.MapperUtils;
import model.DocumentInfo;
import java.util.List;
import utils.JDBCUtils;
import java.util.ArrayList;
import java.sql.*;

public class DocumentInfoMapper {
     
    public static List<DocumentInfo> list() throws Exception{
     
       return  list(null);
    }

    public static List<DocumentInfo> list(DocumentInfo DocumentInfo)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from document_info";
        sql += MapperUtils.getEqualCondition(DocumentInfo);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (Exception throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<DocumentInfo> list = new ArrayList<>();
            while (resultSet.next()) {
     
                DocumentInfo temp = new DocumentInfo();
                temp.setId(resultSet.getInt("id"));
                temp.setName(resultSet.getString("name"));
                temp.setContent(resultSet.getString("content"));
                temp.setDocumentCategory(resultSet.getString("document_category"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static List<DocumentInfo> search(DocumentInfo documentInfo)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from document_info";
        sql += MapperUtils.getLikeCondition(documentInfo);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<DocumentInfo> list = new ArrayList<>();
            while (resultSet.next()) {
     
                DocumentInfo temp = new DocumentInfo();
                temp.setId(resultSet.getInt("id"));
                temp.setName(resultSet.getString("name"));
                temp.setContent(resultSet.getString("content"));
                temp.setDocumentCategory(resultSet.getString("document_category"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }


    public static boolean add(DocumentInfo documentInfo) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "insert into document_info(id,name,content,document_category) values (NULL,?,?,?)";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, documentInfo.getName());
            preparedStatement.setString(2, documentInfo.getContent());
            preparedStatement.setString(3, documentInfo.getDocumentCategory());
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static boolean deleteById(Integer id)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "delete from document_info where id=" + id;
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static int updateById(Integer id, DocumentInfo documentInfo) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "update document_info set ";
        sql += MapperUtils.getUpdateCondition(documentInfo);
        sql += " where id = '" + id + "'";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.executeUpdate();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
}
  • UserInfoMapper
package mapper;

import org.springframework.jdbc.mapper.MapperUtils;
import model.UserInfo;
import java.util.List;
import utils.JDBCUtils;
import java.util.ArrayList;
import java.sql.*;

public class UserInfoMapper {
     
    public static List<UserInfo> list() throws Exception{
     
       return  list(null);
    }

    public static List<UserInfo> list(UserInfo UserInfo)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from user_info";
        sql += MapperUtils.getEqualCondition(UserInfo);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (Exception throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<UserInfo> list = new ArrayList<>();
            while (resultSet.next()) {
     
                UserInfo temp = new UserInfo();
                temp.setId(resultSet.getInt("id"));
                temp.setUsername(resultSet.getString("username"));
                temp.setPassword(resultSet.getString("password"));
                temp.setUserPermissions(resultSet.getString("user_permissions"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }        public static List<UserInfo> search(UserInfo userInfo)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from user_info";
        sql += MapperUtils.getLikeCondition(userInfo);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<UserInfo> list = new ArrayList<>();
            while (resultSet.next()) {
     
                UserInfo temp = new UserInfo();
                temp.setId(resultSet.getInt("id"));
                temp.setUsername(resultSet.getString("username"));
                temp.setPassword(resultSet.getString("password"));
                temp.setUserPermissions(resultSet.getString("user_permissions"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }


    public static boolean add(UserInfo userInfo) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "insert into user_info(id,username,password,user_permissions) values (NULL,?,?,?)";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, userInfo.getUsername());
            preparedStatement.setString(2, userInfo.getPassword());
            preparedStatement.setString(3, userInfo.getUserPermissions());
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static boolean deleteById(Integer id)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "delete from user_info where id=" + id;
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static int updateById(Integer id, UserInfo userInfo) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "update user_info set ";
        sql += MapperUtils.getUpdateCondition(userInfo);
        sql += " where id = '" + id + "'";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.executeUpdate();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
}
  • UserPermissionsMapper
package mapper;

import org.springframework.jdbc.mapper.MapperUtils;
import model.UserPermissions;
import java.util.List;
import utils.JDBCUtils;
import java.util.ArrayList;
import java.sql.*;

public class UserPermissionsMapper {
     
    public static List<UserPermissions> list() throws Exception{
     
       return  list(null);
    }

    public static List<UserPermissions> list(UserPermissions UserPermissions)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from user_permissions";
        sql += MapperUtils.getEqualCondition(UserPermissions);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (Exception throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<UserPermissions> list = new ArrayList<>();
            while (resultSet.next()) {
     
                UserPermissions temp = new UserPermissions();
                temp.setId(resultSet.getInt("id"));
                temp.setUserPermissions(resultSet.getString("user_permissions"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }        public static List<UserPermissions> search(UserPermissions userPermissions)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "select * from user_permissions";
        sql += MapperUtils.getLikeCondition(userPermissions);
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            resultSet = preparedStatement.executeQuery();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        }
        try {
     
List<UserPermissions> list = new ArrayList<>();
            while (resultSet.next()) {
     
                UserPermissions temp = new UserPermissions();
                temp.setId(resultSet.getInt("id"));
                temp.setUserPermissions(resultSet.getString("user_permissions"));

                list.add(temp);
}
return list;
        } catch (Exception e) {
     
            e.printStackTrace();
            throw e;        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }


    public static boolean add(UserPermissions userPermissions) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "insert into user_permissions(id,user_permissions) values (NULL,?)";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            preparedStatement.setString(1, userPermissions.getUserPermissions());
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static boolean deleteById(Integer id)throws Exception {
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "delete from user_permissions where id=" + id;
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.execute();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
    public static int updateById(Integer id, UserPermissions userPermissions) throws Exception{
     
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        ResultSet resultSet = null;
        String sql = "update user_permissions set ";
        sql += MapperUtils.getUpdateCondition(userPermissions);
        sql += " where id = '" + id + "'";
        try {
     
            connection = JDBCUtils.getConnection();
            preparedStatement = connection.prepareStatement(sql);
            return preparedStatement.executeUpdate();
        } catch (SQLException throwables) {
     
            throwables.printStackTrace();
            System.out.printf("===========>>错误:sql=%s<<============%n", sql);
            throw throwables;
        } finally {
     
            JDBCUtils.close(resultSet, preparedStatement, connection);
        }
    }
}
  • DocumentAttachmentServlet
package servlet;

import org.springframework.servelt.BaseServlet;

import model.DocumentAttachment;
import mapper.DocumentAttachmentMapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/documentAttachment")
public class DocumentAttachmentServlet extends BaseServlet {
     
    public void listAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        List<DocumentAttachment> list = DocumentAttachmentMapper.list();
        request.setAttribute("list", list);
        response.sendRedirect(request.getContextPath() + "/DocumentAttachment.jsp");    }    public void deleteById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        DocumentAttachmentMapper.deleteById(Integer.parseInt(id));
        listAll(request, response);
    }
    public void getById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        DocumentAttachment temp = new DocumentAttachment();
        temp.setId(Integer.parseInt(id));
        List<DocumentAttachment> list = DocumentAttachmentMapper.list(temp);
        if (!list.isEmpty()) {
     
            request.getSession().setAttribute("documentAttachment", list.get(0));
        }
        response.sendRedirect(request.getContextPath() + "/DocumentAttachmentAdd.jsp");    }    public void updateById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        DocumentAttachment temp = new DocumentAttachment();
        String id = request.getParameter("id");
        temp.setId(Integer.parseInt(id));
        String name = request.getParameter("name");
        temp.setName(name);
        String path = request.getParameter("path");
        temp.setPath(path);
        String size = request.getParameter("size");
        temp.setSize(Integer.parseInt(size));
        String documentId = request.getParameter("documentId");
        temp.setDocumentId(Integer.parseInt(documentId));
       DocumentAttachmentMapper.updateById(Integer.parseInt(id), temp);
        listAll(request, response);
    }    public void addBean(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        DocumentAttachment temp = new DocumentAttachment();
        String name = request.getParameter("name");
        temp.setName(name);
        String path = request.getParameter("path");
        temp.setPath(path);
        String size = request.getParameter("size");
        temp.setSize(Integer.parseInt(size));
        String documentId = request.getParameter("documentId");
        temp.setDocumentId(Integer.parseInt(documentId));
       DocumentAttachmentMapper.add(temp);
        listAll(request, response);
    }}
  • DocumentCategoryServlet
package servlet;

import org.springframework.servelt.BaseServlet;

import model.DocumentCategory;
import mapper.DocumentCategoryMapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/documentCategory")
public class DocumentCategoryServlet extends BaseServlet {
     
    public void listAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        List<DocumentCategory> list = DocumentCategoryMapper.list();
        request.setAttribute("list", list);
        response.sendRedirect(request.getContextPath() + "/DocumentCategory.jsp");    }    public void deleteById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        DocumentCategoryMapper.deleteById(Integer.parseInt(id));
        listAll(request, response);
    }
    public void getById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        DocumentCategory temp = new DocumentCategory();
        temp.setId(Integer.parseInt(id));
        List<DocumentCategory> list = DocumentCategoryMapper.list(temp);
        if (!list.isEmpty()) {
     
            request.getSession().setAttribute("documentCategory", list.get(0));
        }
        response.sendRedirect(request.getContextPath() + "/DocumentCategoryAdd.jsp");    }    public void updateById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        DocumentCategory temp = new DocumentCategory();
        String id = request.getParameter("id");
        temp.setId(Integer.parseInt(id));
        String name = request.getParameter("name");
        temp.setName(name);
       DocumentCategoryMapper.updateById(Integer.parseInt(id), temp);
        listAll(request, response);
    }    public void addBean(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        DocumentCategory temp = new DocumentCategory();
        String name = request.getParameter("name");
        temp.setName(name);
       DocumentCategoryMapper.add(temp);
        listAll(request, response);
    }}
  • DocumentInfoServlet
package servlet;

import org.springframework.servelt.BaseServlet;

import model.DocumentInfo;
import mapper.DocumentInfoMapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/documentInfo")
public class DocumentInfoServlet extends BaseServlet {
         public void listAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        List<DocumentInfo> list = DocumentInfoMapper.list();
        request.setAttribute("list", list);
        response.sendRedirect(request.getContextPath() + "/DocumentInfo.jsp");    }    public void deleteById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        DocumentInfoMapper.deleteById(Integer.parseInt(id));
        listAll(request, response);
    }
    public void getById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        DocumentInfo temp = new DocumentInfo();
        temp.setId(Integer.parseInt(id));
        List<DocumentInfo> list = DocumentInfoMapper.list(temp);
        if (!list.isEmpty()) {
     
            request.getSession().setAttribute("documentInfo", list.get(0));
        }
        response.sendRedirect(request.getContextPath() + "/DocumentInfoAdd.jsp");    }    public void updateById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        DocumentInfo temp = new DocumentInfo();
        String id = request.getParameter("id");
        temp.setId(Integer.parseInt(id));
        String name = request.getParameter("name");
        temp.setName(name);
        String content = request.getParameter("content");
        temp.setContent(content);
        String documentCategory = request.getParameter("documentCategory");
        temp.setDocumentCategory(documentCategory);
       DocumentInfoMapper.updateById(Integer.parseInt(id), temp);
        listAll(request, response);
    }    public void addBean(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        DocumentInfo temp = new DocumentInfo();
        String name = request.getParameter("name");
        temp.setName(name);
        String content = request.getParameter("content");
        temp.setContent(content);
        String documentCategory = request.getParameter("documentCategory");
        temp.setDocumentCategory(documentCategory);
       DocumentInfoMapper.add(temp);
        listAll(request, response);
    }}
  • LoginOutSevelet
package servlet;

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 java.io.IOException;

@WebServlet("/logout")
public class LoginOutSevelet extends HttpServlet {
     
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     
        req.getSession().removeAttribute("user");
        req.getSession().removeAttribute("error");
        resp.sendRedirect(req.getContextPath() + "/front/login.jsp");
    }
}
  • LoginSevelet
package servlet;

import mapper.UserInfoMapper;
import model.UserInfo;

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 java.io.IOException;
import java.util.List;

@WebServlet("/login")
public class LoginSevelet extends HttpServlet {
     
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        UserInfo login = null;
        try {
     
            UserInfo reader = new UserInfo();
            reader.setUsername(username);
            reader.setPassword(password);
            List<UserInfo> list = UserInfoMapper.list(reader);
            if (!list.isEmpty()) {
     
                login = list.get(0);
            }
        } catch (Exception throwables) {
     
            throwables.printStackTrace();
        }
        if (login == null) {
     
            req.getSession().setAttribute("error", "用户或者密码错误");
            resp.sendRedirect(req.getContextPath() + "/front/login.jsp");
        } else {
     
            req.getSession().setAttribute("user", login);
            if ("管理员".equals(login.getUserPermissions())) {
     
                resp.sendRedirect(req.getContextPath() + "/index.jsp");
            } else {
     
                resp.sendRedirect(req.getContextPath() + "/front/index.jsp");
            }
        }
    }
}
  • Register
package servlet;

import mapper.UserInfoMapper;
import model.UserInfo;

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 java.io.IOException;

@WebServlet("/register")
public class Register extends HttpServlet {
     
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
     
        UserInfo temp = new UserInfo();
        String name = req.getParameter("username");
        temp.setUsername(name);
        String password = req.getParameter("password");
        temp.setPassword(password);
        temp.setUserPermissions("普通用户");
        try {
     
            UserInfoMapper.add(temp);
        } catch (Exception e) {
     
            e.printStackTrace();
            req.getSession().setAttribute("error", "用户名密码错误");
        }
        resp.sendRedirect(req.getContextPath() + "/front/login.jsp");
    }
}
  • UserInfoServlet
package servlet;

import org.springframework.servelt.BaseServlet;

import model.UserInfo;
import mapper.UserInfoMapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/userInfo")
public class UserInfoServlet extends BaseServlet {
     
    public void listAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        List<UserInfo> list = UserInfoMapper.list();
        request.setAttribute("list", list);
        response.sendRedirect(request.getContextPath() + "/UserInfo.jsp");    }    public void deleteById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        UserInfoMapper.deleteById(Integer.parseInt(id));
        listAll(request, response);
    }
    public void getById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        UserInfo temp = new UserInfo();
        temp.setId(Integer.parseInt(id));
        List<UserInfo> list = UserInfoMapper.list(temp);
        if (!list.isEmpty()) {
     
            request.getSession().setAttribute("userInfo", list.get(0));
        }
        response.sendRedirect(request.getContextPath() + "/UserInfoAdd.jsp");    }    public void updateById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        UserInfo temp = new UserInfo();
        String id = request.getParameter("id");
        temp.setId(Integer.parseInt(id));
        String username = request.getParameter("username");
        temp.setUsername(username);
        String password = request.getParameter("password");
        temp.setPassword(password);
        String userPermissions = request.getParameter("userPermissions");
        temp.setUserPermissions(userPermissions);
       UserInfoMapper.updateById(Integer.parseInt(id), temp);
        listAll(request, response);
    }
    public void addBean(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        UserInfo temp = new UserInfo();
        String username = request.getParameter("username");
        temp.setUsername(username);
        String password = request.getParameter("password");
        temp.setPassword(password);
        String userPermissions = request.getParameter("userPermissions");
        temp.setUserPermissions(userPermissions);
       UserInfoMapper.add(temp);
        listAll(request, response);
    }}
  • UserPermissionsServlet
package servlet;

import org.springframework.servelt.BaseServlet;

import model.UserPermissions;
import mapper.UserPermissionsMapper;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/userPermissions")
public class UserPermissionsServlet extends BaseServlet {
         public void listAll(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        List<UserPermissions> list = UserPermissionsMapper.list();
        request.setAttribute("list", list);
        response.sendRedirect(request.getContextPath() + "/UserPermissions.jsp");    }    public void deleteById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        UserPermissionsMapper.deleteById(Integer.parseInt(id));
        listAll(request, response);
    }
    public void getById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        String id = request.getParameter("id");
        UserPermissions temp = new UserPermissions();
        temp.setId(Integer.parseInt(id));
        List<UserPermissions> list = UserPermissionsMapper.list(temp);
        if (!list.isEmpty()) {
     
            request.getSession().setAttribute("userPermissions", list.get(0));
        }
        response.sendRedirect(request.getContextPath() + "/UserPermissionsAdd.jsp");    }    public void updateById(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        UserPermissions temp = new UserPermissions();
        String id = request.getParameter("id");
        temp.setId(Integer.parseInt(id));
        String userPermissions = request.getParameter("userPermissions");
        temp.setUserPermissions(userPermissions);
       UserPermissionsMapper.updateById(Integer.parseInt(id), temp);
        listAll(request, response);
    }    public void addBean(HttpServletRequest request, HttpServletResponse response) throws Exception {
     
        UserPermissions temp = new UserPermissions();
        String userPermissions = request.getParameter("userPermissions");
        temp.setUserPermissions(userPermissions);
       UserPermissionsMapper.add(temp);
        listAll(request, response);
    }}
  • DocumentAttachment
package model;

import java.util.Date;

public class DocumentAttachment {
     
    private Integer id;
public Integer getId() {
     
        return id;
    }
    public void setId(Integer id) {
     
        this.id = id;
    }//Integer的默认值为null
    private String name;
public String getName() {
     
        return name;
    }
    public void setName(String name) {
     
        this.name = name;
    }
    private String path;
public String getPath() {
     
        return path;
    }
    public void setPath(String path) {
     
        this.path = path;
    }
    private Integer size;
public Integer getSize() {
     
        return size;
    }
    public void setSize(Integer size) {
     
        this.size = size;
    }
    private Integer documentId;
public Integer getDocumentId() {
     
        return documentId;
    }
    public void setDocumentId(Integer documentId) {
     
        this.documentId = documentId;
    }
}
  • DocumentCategory
package model;

import java.util.Date;

public class DocumentCategory {
     
    private Integer id;
public Integer getId() {
     
        return id;
    }
    public void setId(Integer id) {
     
        this.id = id;
    }
    private String name;
public String getName() {
     
        return name;
    }
    public void setName(String name) {
     
        this.name = name;
    }
}
  • DocumentInfo
package model;

import java.util.Date;

public class DocumentInfo {
     
    private Integer id;
public Integer getId() {
     
        return id;
    }
    public void setId(Integer id) {
     
        this.id = id;
    }
    private String name;
public String getName() {
     
        return name;
    }
    public void setName(String name) {
     
        this.name = name;
    }
    private String content;
public String getContent() {
     
        return content;
    }
    public void setContent(String content) {
     
        this.content = content;
    }
    private String documentCategory;
public String getDocumentCategory() {
     
        return documentCategory;
    }
    public void setDocumentCategory(String documentCategory) {
     
        this.documentCategory = documentCategory;
    }
}
  • UserInfo
package model;

import java.util.Date;

public class UserInfo {
     
    private Integer id;
public Integer getId() {
     
        return id;
    }
    public void setId(Integer id) {
     
        this.id = id;
    }
    private String username;
public String getUsername() {
     
        return username;
    }
    public void setUsername(String username) {
     
        this.username = username;
    }
    private String password;
public String getPassword() {
     
        return password;
    }
    public void setPassword(String password) {
     
        this.password = password;
    }
    private String userPermissions;
public String getUserPermissions() {
     
        return userPermissions;
    }
    public void setUserPermissions(String userPermissions) {
     
        this.userPermissions = userPermissions;
    }
}
  • UserPermissions
package model;

import java.util.Date;

public class UserPermissions {
     
    private Integer id;
public Integer getId() {
     
        return id;
    }
    public void setId(Integer id) {
     
        this.id = id;
    }
    private String userPermissions;
public String getUserPermissions() {
     
        return userPermissions;
    }
    public void setUserPermissions(String userPermissions) {
     
        this.userPermissions = userPermissions;
    }
}

源代码工程下载

点击此处下载

你可能感兴趣的:(Java,HTML,tomcat,javabean,mysql,web,java)