JavaWeb实现学生管理系统

news2024/11/25 12:58:16

JavaWeb实现学生管理系统

  • 一、项目介绍
  • 二、项目结构
  • 三、前期准备
    • 1.配置maven环境,在pom.xml配置文件中配置项目所依赖的jar包
    • 2.在MySql数据库中,创建登录注册表login和学生信息表student
      • (1)登录注册表login
      • (2)学生信息表student
      • (3)创建数据表代码
    • 3.配置tocamt
  • 四、代码实现
    • 1.JSP界面实现
      • (1)首页-登录界面 (index.jsp)
      • (2)用户注册界面 (register.jsp)
      • (3)登录成功-主界面 (main.jsp)
      • (4)添加学生界面 (addStudent.jsp)
      • (5)分页查询界面(showAllStudentByPageNo.jsp)
      • (6)查看所有学生信息界面
      • (7) 修改学生界面 (updateStudent.jsp)
    • 2.JavaBean实体类封装数据
      • (1)学生信息类 (Student.java)
      • (2)分页帮助类 (Page.java)
      • (3)JDBC工具类 (DBTools.java)
    • 3.三层架构
      • (1)表示层servlet
        • ① 用户登录表示层 (LoginServlet.java)
        • ② 用户注册表示层 (RegisterServlet.java)
        • ③ 分页查询表示层 (ShowStudentsByPageServlet.java)
        • ④ 查询所学生信息表示层 (ShowAllStudentsServlet.java)
        • ⑤ 添加学生表示层 (AddServlet.java)
        • ⑥ 删除学生表示层 (DeleteServlet.java)
        • ⑦ 根据学号查询学生信息表示层 (QueryStudentBySnoSevlet.java)
        • ⑧ 修改学生信息表示层 (UpdateServlet.java)
        • ⑨ 退出登录表示层 (QuitServlet.java)
      • (2)业务逻辑层service
        • ① Service接口(StudentService.java)
        • ② 接口的实现类(StudentServiceImpl.java)
      • (3)数据访问层dao
        • ① 接口(StudentDao.java)
        • ② 接口的实现类(StudentDaoImpl.java)

一、项目介绍

该项目是基于JavaWeb实现的学生管理系统,使用maven进行管理jar包,能够对学生信息进行增删改查,分页查询,以及实现管理员的注册、登录
数据库:MySQL
开发工具:idea
开发环境:jdk 1.8 + tomcat

二、项目结构

在这里插入图片描述在这里插入图片描述

三、前期准备

1.配置maven环境,在pom.xml配置文件中配置项目所依赖的jar包

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

    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>

    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.2</version>
      <scope>provided</scope>
    </dependency>

2.在MySql数据库中,创建登录注册表login和学生信息表student

(1)登录注册表login

在这里插入图片描述

(2)学生信息表student

在这里插入图片描述

(3)创建数据表代码

SET NAMES utf-8;
CREATE DATABASE studentManager;
USE studentManager;
CREATE TABLE student
(
  sno INT PRIMARY KEY,
  sname VARCHAR(20) NOT NULL,
  sex CHAR(4) ,
  age INT DEFAULT 20,
  phone VARCHAR(30) 
);

INSERT INTO student VALUES(1001,'jack','男',23,'13389076524');
INSERT INTO student VALUES(1002,'rose','女',23,'18760987543');
INSERT INTO student VALUES(1003,'tom','男',23,'13389067823');
INSERT INTO student VALUES(1004,'王麻子','男',23,'13560738947');
INSERT INTO student VALUES(1005,'大麻子','男',23,'18899067532');

INSERT INTO student VALUES(1006,'小麻子','男',23,'15678634789');
INSERT INTO student VALUES(1007,'老麻子','男',23,'12199834572');
INSERT INTO student VALUES(1008,'张三','男',23,'15533098843');
INSERT INTO student VALUES(1009,'长萨珊','女',23,'12209835679');
INSERT INTO student VALUES(1010,'李四','女',23,'15509087635');

INSERT INTO student VALUES(1011,'王五','男',23,'15788679043');
INSERT INTO student VALUES(1012,'赵六','女',23,'12489034506');
INSERT INTO student VALUES(1013,'刘二','男',23,'13560596743');

CREATE TABLE login
(
  uid INT PRIMARY KEY,
  pwd VARCHAR(20) NOT NULL,
);

INSERT INTO login VALUES(1, '1234');
INSERT INTO login VALUES(2, '2222');
INSERT INTO login VALUES(3, '6688');

3.配置tocamt

在这里插入图片描述在这里插入图片描述

四、代码实现

1.JSP界面实现

(1)首页-登录界面 (index.jsp)

<%@ page language="java" contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>学生信息管理平台</title>
    <style>

        .titleDiv{
            height: 85px;
            color:white;
            padding-top: 30px;
            font-size: 50px;
            padding-left: 30px;
            font-family: 隶书;
        }

        .mainDiv{
            width: 899px;
            height: 500px;
            border: 4px rgb(237, 237, 237) solid;
            border-radius: 5px;
            background-image: url("输入你要的图片链接!");
            margin: auto;
            margin-top: 50px;
        }

        .loginDiv{
            height: 220px;
            width: 260px;
            padding:50px;
            background-color:rgba(255,255,255,0.9);
            border-radius:25px;
            border:1px #bdbdbd solid;
            opacity:0.9;
            float: right;
            margin-right: 100px
        }

        .name{
            font-size: 25px;
        }

        a{
            font-size:15px;
            color:#59c2c5;
            padding-left:20px;
        }

        .item{
            height:60px;
        }

        .item input{
            line-height:40px;
            width:245px;
            border:none;
            border-bottom: 1px solid #59c2c5;
            margin-bottom: 20px;
            margin-top: 10px;
        }

        .login-btn{
            display:block;
            width:255px;
            height:50px;
            color:#fff;
            background:#59c2c5;
            font-size:16px;
            line-height:30px;
            text-align:center;
            border-radius:10px;
            border:none;
            margin-bottom: 20px;
            margin-top: 10px;
        }
    </style>



</head>

<body>

<div class="mainDiv">
    <div class="titleDiv">学生信息管理平台</div>

    <form action="LoginServlet" method="post">
    <div class="loginDiv">
        <div class="name">
            用户登录 <a href="register.jsp"> 立即注册</a>
        </div>

        <div class=item>
            <input type="text" name="uid" placeholder="用户名"/>
        </div>
        <div class=item>
            <input type="password" name="pwd" placeholder="密码"/>
        </div>
        <input type="submit" class="login-btn" value="登 录"/>
        <%
            if(session.getAttribute("loginErrorMessage") != null){

                String loginErrorMessage = (String)session.getAttribute("loginErrorMessage");
                out.print(loginErrorMessage);
            }
        %>
        <%
            String register = (String) request.getAttribute("register");
            if (register!= null) {
                if (register.equals("reg")) {
                    out.println("注册成功, 请登录!");
                }
            }
        %>
    </div>
    </form>
</div>
</body>
</html>

(2)用户注册界面 (register.jsp)

<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <title>注册账号</title>

    <style>
        .mainDiv{
            width: 899px;
            height: 500px;
            border: 4px rgb(237, 237, 237) solid;
            border-radius: 5px;
            background-image: url("输入你要的图片链接!");
            margin: auto;
            margin-top: 50px;
        }


        .titleDiv{
            height: 85px;
            color:white;
            padding-top: 30px;
            font-size: 50px;
            padding-left: 30px;
            font-family: 隶书;
        }

        .registerDiv{
            height: 220px;
            width: 260px;
            padding:50px;
            background-color:rgba(255,255,255,0.9);
            border-radius:25px;
            border:1px #bdbdbd solid;
            opacity:0.9;
            float: right;
            margin-right: 100px
        }

        .name{
            font-size: 25px;
        }

        .item{
            height:60px;
        }

        .item input{
            line-height:40px;
            width:245px;
            border:none;
            border-bottom: 1px solid #59c2c5;
            margin-bottom: 20px;
            margin-top: 10px;
        }

        .btn{
            display:block;
            width:255px;
            height:50px;
            color:#fff;
            background:#59c2c5;
            font-size:16px;
            line-height:30px;
            text-align:center;
            border-radius:10px;
            border:none;
            margin-top: 10px;
        }

        a{
            font-size:18px;
            padding-left:200px;
            padding-bottom: 50px;
            color:#59c2c5;

        }


    </style>
</head>

</head>
<body>
<div class="mainDiv">
    <div class="titleDiv">学生信息管理平台</div>
    <form action = "RegisterServlet">
        <div class = "registerDiv">
            <div class = "name">用户注册</div>
            <div class = "item">
                <input type = "text" name = "uid" placeholder="账号"/>
            </div>
            <div class = "item">
                <input type = "password" name = "pwd"  placeholder="密码"/>
            </div>
            <input type = "submit" class = "btn" value = "注册"/>
            <a href = "index.jsp" >返回</a>

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

(3)登录成功-主界面 (main.jsp)

<%@ page language="java" contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%>
<%@ page import="com.stu.po.Student" %>
<!DOCTYPE html>
<html >
<head>
    <title>学生信息管理平台</title>

    <style>
        .titleDiv{
            height: 85px;
            color:white;
            padding-top: 30px;
            font-size: 50px;
            padding-left: 30px;
            font-family: 隶书;
        }

        .mainDiv{
            width: 899px;
            height: 500px;
            border: 4px rgb(237, 237, 237) solid;
            border-radius: 5px;
            background-image: url("https://img1.baidu.com/it/u=4271373647,1745018175&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500");
            margin: auto;
            margin-top: 50px;
            background-size: auto;
        }

        .Navigation{
            width: 899px;
            height: 200px;
            background-color:#59c2c5;
            opacity:0.8;
            text-align: center;
            line-height: 200px;
            font-family: 楷体;

        }

        a{
            font-size:30px;
            color:whitesmoke;
            padding-left:20px;
            text-decoration: none;
        }

        a:hover{
            color: blue;
            font-family: 隶书;
        }

    </style>
</head>
<body>
<div class="mainDiv">
    <div class="titleDiv">欢迎进入学生信息管理平台</div>
    <%
        if(session.getAttribute("login") == null) {
            session.setAttribute("loginErrorMessage", "您必须先登录才能访问主页!");
            response.sendRedirect("index.jsp");
        }
    %>
    <div class="Navigation">
        <a href="addStudent.jsp">添加学生</a>
        <a href="ShowStudentsByPageServlet">分页查询</a>
        <a href="ShowAllStudentsServlet">查看所有学生信息</a>
        <a href="QuitServlet">退出登录</a>
    </div>
</div>
</body>
</html>

(4)添加学生界面 (addStudent.jsp)

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>添加学生信息</title>

    <style>
        .titleDiv{
            height: 2px;
            color:white;
            padding-top: 12px;
            font-size: 50px;
            padding-left: 30px;
            font-family: 隶书;
        }

        .mainDiv{
            width: 899px;
            height: 500px;
            border: 4px rgb(237, 237, 237) solid;
            border-radius: 5px;
            background-image: url("图片链接");
            margin: auto;
            margin-top: 50px;
            background-size: auto;
        }

        .addDiv{
            height: 380px;
            width: 260px;
            padding:50px;
            background-color:rgba(255,255,255,0.9);
            border-radius:25px;
            border:1px #bdbdbd solid;
            opacity:0.9;
            float: right;
            margin-right: 80px
        }

        .name{
            font-size: 20px;

        }

        .item{
            height:60px;
        }

        .item input{
            line-height:40px;
            width:245px;
            border:none;
            border-bottom: 1px solid #59c2c5;
            margin-bottom: 20px;
            margin-top: 10px;
        }

        .btn{
            display:block;
            width:255px;
            height:50px;
            color:#fff;
            background:#59c2c5;
            font-size:16px;
            line-height:30px;
            text-align:center;
            border-radius:10px;
            border:none;
            margin-top: 10px;
        }

        a{
            font-size:18px;
            padding-left:200px;
            padding-bottom: 50px;
            color:#59c2c5;

        }

    </style>
</head>

<body>
<div class="mainDiv">
    <div class="titleDiv">学生信息管理平台</div>
    <form action = "AddServlet">
        <div class = "addDiv">
            <div class = "name">添加学生信息</div>

            <div class = "item">
                <input type = "text" name="sno" placeholder="学号"/>
            </div>
            <div class = "item">
                <input type = "text" name="sname" placeholder="姓名"/>
            </div>
            <div class = "item">
                <input type = "text" name="sex" placeholder="性别"/>
            </div>
            <div class = "item">
                <input type = "text" name="age" placeholder="年龄"/>
            </div>
            <div class = "item">
                <input type = "text" name="phone" placeholder="电话"/>
            </div>
            <input type = "submit" class = "btn" value = "添加"/>
            <a href = "main.jsp">返回</a>
        </div>
    </form>
</div>
</div>
</body>
</html>

(5)分页查询界面(showAllStudentByPageNo.jsp)

<%@ page import="com.stu.po.Student" %>
<%@ page import="java.util.List" %>
<%@ page import="com.stu.po.Page" %>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>

  <title>学生信息管理平台</title>

  <style>
    .mainDiv{
      width: 900px;
      height: 550px;
      border: 4px rgb(237, 237, 237) solid;
      border-radius: 5px;
      background-image: url("图片链接");
      margin: auto;
      background-size: auto;
    }

    .titleDiv{
      height: 20px;
      color:white;
      padding-top: 30px;
      font-size: 50px;
      padding-left: 30px;
      font-family: 隶书;
    }

    .showStudentDiv{
      background-size: cover;
      width:700px;
      height:500px;
      margin: auto;
      margin-top: 50px;

    }

    .item{
      height:40px;
      border-radius:15px;
    }

    .item a{
      background-color: lightgrey;
      text-decoration: none;
      font-size:15px;
      color:black;
      border-radius:3px;
    }

    .item input{
      width: 20px;
      text-align: center;
    }


    table{
      width:100%;
      border-collapse:collapse;
      background-color: rgba(255,255,255,0.9);
      opacity: 0.8;
    }


    table body{
      display: block;
      height:300px;
      overflow-y: scroll;
    }
    table td{
      border:1px solid #A6A6A6;
      height:30px;
      width: 300px;
      text-align: center;
      font-size: 15px;
    }
    table th{
      height:30px;
      border:1px solid #A6A6A6;
    }

  </style>
</head>
<body>
<div class="mainDiv">
  <div class="titleDiv">分页查询学生信息</div>
    <div class = "showStudentDiv">
      <table  border="2" cellspacing="0">
        <tr>
          <th><h3>学号</h3></th>
          <th><h3>姓名</h3></th>
          <th><h3>性别</h3></th>
          <th><h3>年龄</h3></th>
          <th><h3>电话</h3></th>

        </tr>
        <%
          Page page1 = (Page)request.getAttribute("page1");

          for(Student student:page1.getStudent()){

        %>
            <tr>
              <td><%=student.getSno() %></td>
              <td><%=student.getSname() %></td>
              <td><%=student.getSex() %></td>
              <td><%=student.getAge() %></td>
              <td><%=student.getPhone() %></td>
            </tr>
          <%
            }
          %>
      </table>

      <%
        if(page1.getCurrentPage()==page1.getTotalPage()){
      %>
        <div class = item>
          <a href = "ShowStudentsByPageServlet?currentPage=0">首页</a>
          <a href = "ShowStudentsByPageServlet?currentPage=<%=page1.getCurrentPage()-1%>">上一页</a>
          <input type = "text" name = "currentPage" value="<%=page1.getTotalPage()+1%>"/>
        </div>
      <%
      } else if(page1.getCurrentPage()==0){
      %>
        <div class = item>
          <input type = "text" name = "currentPage" value="1"/>
          <a href = "ShowStudentsByPageServlet?currentPage=<%=page1.getCurrentPage()+1%>">下一页</a>
          <a href = "ShowStudentsByPageServlet?currentPage=<%=page1.getTotalPage()%>">尾页</a>
        </div>
      <%
      } else{
      %>
        <div class = item>
          <a href = "ShowStudentsByPageServlet?currentPage=0">首页</a>
          <a href = "ShowStudentsByPageServlet?currentPage=<%=page1.getCurrentPage()-1%>">上一页</a>
          <input type = "text" name = "currentPage" value="<%=page1.getCurrentPage()+1%>"/>
          <a href = "ShowStudentsByPageServlet?currentPage=<%=page1.getCurrentPage()+1%>">下一页</a>
          <a href = "ShowStudentsByPageServlet?currentPage=<%=page1.getTotalPage()%>">尾页</a>
        </div>
      <%
        }
      %>

      <a href = "main.jsp">返回</a>
    </div>
</div>
</body>
</html>

(6)查看所有学生信息界面

<%@ page language="java" contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%>
<%@ page import="com.stu.po.Student" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html>
<head>
	<title>学生信息管理平台</title>

	<style>
		.mainDiv{
			width: 900px;
			height: 700px;
			border: 4px rgb(237, 237, 237) solid;
			border-radius: 5px;
			background-image: url("图片链接");
			margin: auto;
			background-size: auto;
		}

		.titleDiv{
			height: 20px;
			color:white;
			padding-top: 30px;
			font-size: 50px;
			padding-left: 30px;
			font-family: 隶书;
		}

		.showStudentDiv{
			background-size: cover;
			width:700px;
			height:500px;
			margin: auto;
			margin-top: 50px;

		}

		.item{
			height:40px;
			border-radius:15px;
		}

		.item a{
			background-color: lightgrey;
			text-decoration: none;
			font-size:15px;
			color:black;
			border-radius:3px;
		}


		table{
			width:100%;
			border-collapse:collapse;
			background-color: rgba(255,255,255,0.9);
			opacity: 0.8;
		}


		table body{
			display: block;
			height:300px;
			overflow-y: scroll;
		}
		table td{
			border:1px solid #A6A6A6;
			height:30px;
			width: 300px;
			text-align: center;
			font-size: 15px;
		}
		table th{
			height:30px;
			border:1px solid #A6A6A6;
		}



	</style>
</head>
<body>
<div class="mainDiv">
	<div class="titleDiv">查看所有学生信息</div>
	<div class = "showStudentDiv">
		<table  border="2" cellspacing="0">
			<tr>
				<th><h3>学号</h3></th>
				<th><h3>姓名</h3></th>
				<th><h3>性别</h3></th>
				<th><h3>年龄</h3></th>
				<th><h3>电话</h3></th>
				<th><h3>操作</h3></th>
			</tr>
			<%

				List<Student> allStudents = (List<Student>)session.getAttribute("allStudents");
				for (int i = 0; i < allStudents.size(); i++) {
					Student s  = allStudents.get(i);
			%>
			<tr>
				<td><%=s.getSno() %></td>
				<td><%=s.getSname() %></td>
				<td><%=s.getSex() %></td>
				<td><%=s.getAge() %></td>
				<td><%=s.getPhone() %></td>
				<td>
					<a href = "DeleteServlet?sno=<%=s.getSno() %>">删除</a>
					<a href = "QueryStudentBySnoServlet?sno=<%=s.getSno()%>">修改</a>
				</td>
			</tr>
			<%
				}
			%>
		</table>
		<a href = "main.jsp">返回</a>
	</div>

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

(7) 修改学生界面 (updateStudent.jsp)

<%@ page language="java" contentType="text/html; charset=utf-8"  pageEncoding="utf-8"%>
<%@ page import="com.stu.po.Student" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>修改学生信息</title>

    <style>
        .titleDiv{
            height: 20px;
            color:white;
            padding-top: 30px;
            font-size: 50px;
            padding-left: 30px;
            font-family: 隶书;
        }

        .mainDiv{
            width: 899px;
            height: 500px;
            border: 4px rgb(237, 237, 237) solid;
            border-radius: 5px;
            background-image: url("https://img1.baidu.com/it/u=4271373647,1745018175&fm=253&fmt=auto&app=138&f=JPEG?w=889&h=500");
            margin: auto;
            margin-top: 50px;
            background-size: auto;
        }

        .updateDiv{
            height: 340px;
            width: 260px;
            padding:50px;
            background-color:rgba(255,255,255,0.9);
            border-radius:25px;
            border:1px #bdbdbd solid;
            opacity:0.9;
            float: right;
            margin-right: 100px
        }

        .name{
            font-size: 25px;
        }

        .item{
            height:60px;
        }

        .item input{
            line-height:40px;
            width:245px;
            border:none;
            border-bottom: 1px solid #59c2c5;
            margin-bottom: 20px;
            margin-top: 10px;
        }

        .btn{
            display:block;
            width:255px;
            height:50px;
            color:#fff;
            background:#59c2c5;
            font-size:16px;
            line-height:30px;
            text-align:center;
            border-radius:10px;
            border:none;
            margin-top: 10px;
        }

        a{
            font-size:18px;
            padding-right:100px;
            padding-bottom: 50px;
        }

    </style>
</head>

<body>
<div class="mainDiv">
    <div class="titleDiv">学生信息管理平台</div>

    <form action = "UpdateServlet">
        <%
            Student s =(Student)request.getAttribute("student");
        %>
        <div class = "updateDiv">
            <div class = "name">修改学生信息</div>
            <input type="hidden" name="sno" value="<%=s.getSno()%>"/>
            <div class = "item">
                <input type = "text" name="sname" placeholder="姓名" value="<%=s.getSname()%>"/>
            </div>
            <div class = "item">
                <input type = "text" name="sex" placeholder="性别" value="<%=s.getSex()%>"/>
            </div>
            <div class = "item">
                <input type = "text" name="age" placeholder="年龄" value="<%=s.getAge()%>"/>
            </div>
            <div class = "item">
                <input type = "text" name="phone" placeholder="电话" value="<%=s.getPhone()%>"/>
            </div>
            <input type = "submit" class = "btn" value = "修改"/>
            <a href = "showAllStudents.jsp">返回</a>
        </div>
    </form>
</div>
</div>
</body>
</html>

2.JavaBean实体类封装数据

(1)学生信息类 (Student.java)

package com.stu.po;

public class Student {
    //这是一个实体类,javabean

    private int sno;
    private String sname;
    private String sex;
    private int age;
    private String phone;

    public Student(int sno, String sname, String sex, int age, String phone) {
        this.sno = sno;
        this.sname = sname;
        this.sex = sex;
        this.age = age;
        this.phone = phone;
    }

    public Student() {

    }

    public int getSno() {
        return sno;
    }

    public void setSno(int sno) {
        this.sno = sno;
    }

    public String getSname() {
        return sname;
    }

    public void setSname(String sname) {
        this.sname = sname;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }
}

(2)分页帮助类 (Page.java)

package com.stu.po;

import java.util.List;

//分页帮助类
public class Page {
    private int currentPage;  //当前页面
    private int pageSize;     //一页有多少条数据
    private int totalCount;   //一共有多少条数据
    private int totalPage;    //一共有多少页
    private List<Student> student;
    public Page() {

    }
    public Page(int currentPage, int pageSize, int totalCount, int totalPage, List<Student> student) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPage = totalPage;
        this.student = student;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public List<Student> getStudent() {
        return student;
    }

    public void setStudent(List<Student> student) {
        this.student = student;
    }
}

(3)JDBC工具类 (DBTools.java)

package com.stu.utils;

public interface DBTools {
    public static final String DRIVER_CLASS = "com.mysql.jdbc.Driver";
    public static final String CONN_STR = "jdbc:mysql://localhost:3306/studentmanager?userSSL=false&serverTimezone=Asia/Shanghai";
    public static final String USRENAME = "root";
    public static final String PWD = "123456";

}

3.三层架构

(1)表示层servlet

① 用户登录表示层 (LoginServlet.java)

package com.stu.servlet;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.stu.po.Student;
import com.stu.service.StudentService;
import com.stu.service.StudentServiceImpl;

@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        StudentService service = new StudentServiceImpl();
        HttpSession session = request.getSession();

        if (session.getAttribute("loginErrorMessage") != null) {
            session.invalidate();
        }
        String uid = request.getParameter("uid");
        String pwd = request.getParameter("pwd");


        int _uid = Integer.parseInt(uid);
        boolean result = service.login(_uid, pwd);

        if(result){
            session.setAttribute("login", "log");
            response.sendRedirect("main.jsp");
        }else{
            response.sendRedirect("index.jsp");
        }

    }

}

② 用户注册表示层 (RegisterServlet.java)

package com.stu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.stu.po.Student;
import com.stu.service.StudentService;
import com.stu.service.StudentServiceImpl;

@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        StudentService service = new StudentServiceImpl();
        String uid = request.getParameter("uid");
        String pwd = request.getParameter("pwd");
        int _uid = Integer.parseInt(uid);
        boolean result = service.addLogin(_uid,pwd);

        if(!result) {
            request.setAttribute("register", "reg");
            request.getRequestDispatcher("index.jsp").forward(request, response);
        }else {
            request.getRequestDispatcher("register.jsp").forward(request, response);
        }

    }

}

③ 分页查询表示层 (ShowStudentsByPageServlet.java)

package com.stu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.stu.po.Page;
import com.stu.po.Student;
import com.stu.service.StudentService;
import com.stu.service.StudentServiceImpl;

@WebServlet("/ShowStudentsByPageServlet")
public class ShowStudentsByPageServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StudentService Service = new StudentServiceImpl();
        int count = Service.getTotalCount();

        Page page = new Page();


        String currentPage = request.getParameter("currentPage");

        if(currentPage == null) {
            currentPage = "0";
        }
        int _currentPage = Integer.parseInt(currentPage);
        page.setCurrentPage(_currentPage);

        int totalCount = Service.getTotalCount();
        page.setTotalCount(totalCount);


        int pageSize = 5;
        int totalPage = (totalCount / pageSize) + 1;
        page.setTotalPage(totalPage+1);


        page.setPageSize(pageSize);

        List<Student> student = Service.queryStudentsByPageNo(_currentPage, pageSize);
        page.setStudent(student);

        request.setAttribute("page1", page);
        request.getRequestDispatcher("showAllStudentsByPageNo.jsp").forward(request, response);
    }

}

④ 查询所学生信息表示层 (ShowAllStudentsServlet.java)

package com.stu.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.stu.po.Student;
import com.stu.service.StudentService;
import com.stu.service.StudentServiceImpl;

@WebServlet("/ShowAllStudentsServlet")
public class ShowAllStudentsServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StudentService service = new StudentServiceImpl();
        HttpSession  session =   request.getSession();
        List<Student> allStudents = service.getAllStudents();
        session.setAttribute("allStudents", allStudents);
        response.sendRedirect("showAllStudents.jsp");
    }

}

⑤ 添加学生表示层 (AddServlet.java)

package com.stu.servlet;

import com.stu.po.Student;
import com.stu.service.StudentService;
import com.stu.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        StudentService service = new StudentServiceImpl();
        String sno  = request.getParameter("sno");
        String sname  = request.getParameter("sname");
        String sex  = request.getParameter("sex");
        String age  = request.getParameter("age");
        String phone  = request.getParameter("phone");

        int _sno = 0;
        if(sno != null || "".equals(sno)){
            _sno = Integer.parseInt(sno);
        }

        int _age = 0;
        if (age !=null || "".equals(age)){
            _age = Integer.parseInt(age);
        }

        Student s = new Student(_sno, sname, sex, _age, phone);
        int result = service.addStudent(s);

        HttpSession session = request.getSession();
        session.setAttribute("student", "stu");
        response.sendRedirect("main.jsp");

    }
}

⑥ 删除学生表示层 (DeleteServlet.java)

package com.stu.servlet;

import com.stu.po.Student;
import com.stu.service.StudentService;
import com.stu.service.StudentServiceImpl;

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("/DeleteServlet")
public class DeleteServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取sno
        String sno = request.getParameter("sno");

        int _sno = 0;
        if(sno != null && !"".equals(sno)){
            _sno = Integer.parseInt(sno);
        }

        //2.执行删除
        StudentService service = new StudentServiceImpl();
        Student stu = service.deleteStudent(_sno);
        //3.跳转到列表页
        request.setAttribute("stu", stu);
        request.getRequestDispatcher("ShowAllStudentsServlet").forward(request,response);
    }
}

⑦ 根据学号查询学生信息表示层 (QueryStudentBySnoSevlet.java)

package com.stu.servlet;

import com.stu.po.Student;
import com.stu.service.StudentService;
import com.stu.service.StudentServiceImpl;

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("/QueryStudentBySnoServlet")
public class QueryStudentBySnoServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取sno;
        String sno = request.getParameter("sno");
        int _sno = 0;
        if(sno != null && !"".equals(sno)){
            _sno = Integer.parseInt(sno);
        }

        //2.查询学生数据
        StudentService service = new StudentServiceImpl();
        Student student = service.queryStudentBySno(_sno);

        //3.显示数据
        //存数据
        request.setAttribute("student", student);
        //跳转
        request.getRequestDispatcher("updateStudent.jsp").forward(request,response);

    }
}

⑧ 修改学生信息表示层 (UpdateServlet.java)

package com.stu.servlet;

import com.stu.po.Student;
import com.stu.service.StudentService;
import com.stu.service.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/UpdateServlet")
public class UpdateServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {

        String sno = request .getParameter("sno");
        String sname  = request.getParameter("sname");
        String sex  = request.getParameter("sex");
        String age  = request.getParameter("age");
        String phone  = request.getParameter("phone");

        int _sno = 0;
        if(sno != null && !"".equals(sno)){
            _sno = Integer.parseInt(sno);
        }
        int _age = 0;
        if(age != null && !"".equals(age)){
            _age = Integer.parseInt(age);
        }


        Student stu = new Student(_sno, sname, sex, _age, phone);

        StudentService service = new StudentServiceImpl();
        service.updateStudentBySno(_sno,stu);

        //3.跳转界面
        request.getRequestDispatcher("ShowAllStudentsServlet").forward(request, resp);

    }
}

⑨ 退出登录表示层 (QuitServlet.java)

package com.stu.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


@WebServlet("/QuitServlet")
public class QuitServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession  session =   request.getSession();
        session.invalidate();//清空session对象中的所有属性数据内容
        resp.sendRedirect("index.jsp");
    }
}


(2)业务逻辑层service

① Service接口(StudentService.java)

package com.stu.service;

import java.util.List;

import com.stu.po.Student;

public interface StudentService {

    //service表示业务逻辑层,定义的每一个方法实际上对应的就是用户的一个需求(请求)

    public boolean login(int uid,String pwd);

    public boolean addLogin(int uid, String pwd);

    public List<Student> getAllStudents();

    public List<Student> queryStudentsByPageNo(int current, int pageSize);

    public Student deleteStudent(int sno);

    public Student queryStudentBySno(int sno);

    public int updateStudentBySno(int sno, Student stu) ;

    public int getTotalCount();

    public int addStudent(Student student);
    
}

② 接口的实现类(StudentServiceImpl.java)

package com.stu.service;

import java.util.List;
import com.stu.dao.StudentDao;
import com.stu.dao.StudentDaoImpl;
import com.stu.po.Student;

public class StudentServiceImpl implements StudentService {

    StudentDao dao = new StudentDaoImpl();

    //登陆
    @Override
    public boolean login(int uid, String pwd) {
        return dao.login(uid, pwd);
    }

    // 注册
    @Override
    public boolean addLogin(int uid, String pwd){
        return dao.addLogin(uid, pwd);
    }

    // 查询所有学生
    @Override
    public List<Student> getAllStudents() {
        return dao.getAllStudents();
    }

    // 分页查询
    @Override
    public List<Student> queryStudentsByPageNo(int current, int pageSize) {
        return dao.queryStudentByPage(current,pageSize);
    }

    // 删除学生
    @Override
    public Student deleteStudent(int sno){
        return dao.deleteStudent(sno);
    }

    // 修改学生信息,要先根据学号查询学生信息
    public Student queryStudentBySno(int sno) {
        return dao.queryStudentBySno(sno);

    }

    //更改学生信息
    public int updateStudentBySno(int sno, Student stu) {
        return dao.updateStudentBySno(sno,stu);
    }
    
    //查询总条数
    @Override
    public int getTotalCount() {
        return dao.getTotalCount();
    }

    @Override
    public int addStudent(Student student) {
        return dao.addStudent(student);
    }
    
}

(3)数据访问层dao

① 接口(StudentDao.java)

package com.stu.dao;

import java.util.List;

import com.stu.po.Student;

public interface StudentDao {

    public boolean login(int uid ,String pwd);

    public boolean addLogin(int uid, String pwd);

    public List<Student> getAllStudents();

    public List<Student> queryStudentByPage(int currentPage,int pageSize);

    public Student deleteStudent(int sno);

    public Student queryStudentBySno(int sno);

    public int updateStudentBySno(int sno,Student stu);

    //查询总数据数
    public int getTotalCount();

    public int addStudent(Student student);
   
}

② 接口的实现类(StudentDaoImpl.java)

package com.stu.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import com.stu.po.Student;
import com.stu.utils.DBTools;

public class StudentDaoImpl implements StudentDao {

    Connection conn = null; // 连接对象
    Statement st = null; // 语句对象
    ResultSet rs = null; // 结果集合对象

    @Override
    public boolean login(int uid, String pwd) {
        // 在这里需要连接数据库,根据int sno, String pwd这两个参数来查询student表
        // jdbc
        // 1:配置环境,下载数据库连接驱动jar文件,拷贝到项目中来
        // 2:加载驱动,根据驱动创建数据库的连接对象

        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动

            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);
            // 3:执行sql语句,完成对数据库中表的数据的增删该查。必须创建一个语句对象(执行sql语句的)
            st = conn.createStatement();

            int count = 0;
            String sqlStr = "select * from login where uid =" + uid + " and pwd = '" + pwd + "'";

            rs = st.executeQuery(sqlStr);
            while(rs.next()) {
                count++;
            }
            if(count>0)
                return true;
            else
                return false;

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }


    @Override
    public List<Student> getAllStudents() {
        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动

            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);
            // 3:执行sql语句,完成对数据库中表的数据的增删该查。必须创建一个语句对象(执行sql语句的)
            st = conn.createStatement();

            String sqlStr = "select * from student";

            rs = st.executeQuery(sqlStr);

            List<Student> allStudents = new ArrayList<Student>();

            while (rs.next()) {
                int _sno = rs.getInt(1);
                String _sname = rs.getString(2);
                String _sex = rs.getString(3);
                int _age = rs.getInt(4);
                String _phone = rs.getString(5);
                Student s = new Student(_sno, _sname, _sex, _age, _phone);
                allStudents.add(s);
            }

            return allStudents;

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }


    public List<Student> queryStudentByPage(int current, int pageSize) {
        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动

            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);
            // 3:执行sql语句,完成对数据库中表的数据的增删该查。必须创建一个语句对象(执行sql语句的)
            st = conn.createStatement();

            int startPosition = current * pageSize;

            String sqlStr = "select * from student limit " + startPosition + "," + pageSize;
            rs = st.executeQuery(sqlStr);
            List<Student> allStudents = new ArrayList<Student>();
            while (rs.next()) {
                int _sno = rs.getInt(1);
                String _sname = rs.getString(2);
                String _sex = rs.getString(3);
                int _age = rs.getInt(4);
                String _phone = rs.getString(5);
                Student s = new Student(_sno, _sname, _sex, _age, _phone);
                allStudents.add(s);
            }
            return allStudents;
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return null;
    }

    public int getTotalCount() {//查询总数据数

        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动

            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);
            // 3:执行sql语句,完成对数据库中表的数据的增删该查。必须创建一个语句对象(执行sql语句的)
            st = conn.createStatement();
            String sql = "select count(*) from student";
            rs = st.executeQuery(sql);
            while (rs.next()){
                int totalCount = rs.getInt(1);
            }


        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public int addStudent(Student student) {

        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动

            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);
            st = conn.createStatement();
            String sqlStr = "insert into student values("+student.getSno()+",'" + student.getSname()+ "','" + student.getSex() +"',"+student.getAge()+",'"+student.getPhone()+"')";
            System.out.println(sqlStr);
            int result = st.executeUpdate(sqlStr);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return 0;
    }


    @Override
    public boolean addLogin(int uid, String pwd) {
        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动

            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);
            st = conn.createStatement();
            String sqlStr = "insert into login values(" + uid + ",'" + pwd + "')";

            int result = st.executeUpdate(sqlStr);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }


    @Override
    public Student deleteStudent(int sno) {
        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动
            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);
            st = conn.createStatement();
            String sqlStr = "delete from student where sno = " + sno;
            System.out.println(sqlStr);
            int result = st.executeUpdate(sqlStr);

        } catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public Student queryStudentBySno(int sno) {
        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动

            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);

            st = conn.createStatement();

            String sqlStr = "select * from student where sno = "+ sno;
            rs = st.executeQuery(sqlStr);

            if (rs.next()) {
                int _sno = rs.getInt(1);
                String _sname = rs.getString(2);
                String _sex = rs.getString(3);
                int _age = rs.getInt(4);
                String _phone = rs.getString(5);
                Student s = new Student(_sno, _sname, _sex, _age, _phone);
                return s;
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    @Override
    public int updateStudentBySno(int sno, Student stu){
        try {
            Class.forName(DBTools.DRIVER_CLASS);// 加载驱动
            conn = DriverManager.getConnection(DBTools.CONN_STR, DBTools.USRENAME, DBTools.PWD);
            st = conn.createStatement();
            String sql = "update student set sname= '"+stu.getSname()+"', sex='"+stu.getSex()+"', age="+stu.getAge()+", phone='"+stu.getPhone()+"' where sno="+sno;
            System.out.println(sql);
            int result = st.executeUpdate(sql);

        } catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }
}

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【C++】继承 | 基类和派生类对象赋值转换 | 派生类的默认成员函数 | 菱形继承

目录 1.继承的概念及定义 1.1继承的概念 1.2 继承定义 1.2.1定义格式 1.2.2继承关系和访问限定符 1.2.3继承基类成员访问方式的变化 2.基类和派生类对象赋值转换 3.继承中的作用域 4.派生类的默认成员函数 5.继承与友元 6. 继承与静态成员 7. 菱形继承 1.继承的概念…

【InsCode Stable Diffusion美图活动一期】——海边跳舞的少女

✅作者简介&#xff1a;2022年博客新星 第八。热爱国学的Java后端开发者&#xff0c;修心和技术同步精进。 &#x1f34e;个人主页&#xff1a;Java Fans的博客 &#x1f34a;个人信条&#xff1a;不迁怒&#xff0c;不贰过。小知识&#xff0c;大智慧。 &#x1f49e;当前专栏…

window平台下MSVC2015编译Libyuv静态库 动态库

window平台下MSVC2015编译Libyuv静态库 动态库 编译步骤一、环境准备1.1 下载libyuv源码1.2 下载安装cmake&#xff1a;1.3 安装MobaXterm&#xff08;终端工具&#xff09; 二、编译生成静态&#xff0c;动态库2.1 cmake编译生成Visual Studio工程2.2 使用Visual Studio打开YU…

怎么从视频中提取音频?分享三个方法给大家!

如何从视频中提取音频&#xff1f;当我们观看视频时&#xff0c;经常会听到很好听的音乐&#xff0c;或者希望下载视频课程的音频以便随时学习。有时候&#xff0c;某些音频可能没有单独的音源或无法下载。那么&#xff0c;有什么方法可以将视频中的音频提取出来呢&#xff1f;…

第五章:Mask R-CNN网络详解

(目标检测篇&#xff09;系列文章目录 第一章:R-CNN网络详解 第二章:Fast R-CNN网络详解 第三章:Faster R-CNN网络详解 第四章:SSD网络详解 第五章:Mask R-CNN网络详解 第六章:YOLO v1网络详解 第七章:YOLO v2网络详解 第八章:YOLO v3网络详解 文章目录 系列文章目录技…

Openlayers实战:自定义放大缩小,显示zoom等级

Openlayers地图中,默认的zoom组件是在左上角,这个组件很重要,方便大家来操控地图。在实际项目中,大家往往要改写这个组件,通常会放置到右下角,方便鼠标操作。 在我们的实战课程里,自定义了放大缩小,并增加了显示zoom等级的功能,实际的项目中往往都是这样办理的。 效果…

4、CCesium鼠标点击事件

在地图中添加鼠标点击事件&#xff0c;与web端cesium基本类似&#xff0c;我们使用上一个的示例&#xff0c;在上一个的示例中进行修改。 1、建一个类Handler&#xff0c;类中又个静态函数mouseUp&#xff0c;函数只在控制台输出信息 2、声明变量handler&#xff0c;并创建Scr…

java环境配置为1.8jdk为什么cmd java -version查看版本是17或者11

1、查看你的环境变量中Path的配置&#xff0c;确认%java_home%/bin在path值的第一个。 2、在cmd中输入echo %path%&#xff0c;看一下实际有效的path值是什么&#xff0c;其中的java配置对不对 3、oracle也自带一个jdk&#xff0c;如果你在配置环境变量时&#xff0c;将jdk配在…

m4a格式怎么转换成mp3,这几个方法分享给大家!

m4a是一种音频格式&#xff0c;它与mp3格式有一些区别。据说m4a是AAC的扩展名之一&#xff0c;它是Apple对MP3的回应&#xff0c;主要用于Mac环境下的压缩音频格式。随着iTunes Store的兴起&#xff0c;m4a在通过在线音乐商店购买音乐方面变得非常流行。然而&#xff0c;尽管许…

正则表达式测试(一)

一、匹配上1,2,3 三种字符串 测试地址&#xff1a;访问 二、匹配上1,2,3 三种字符串 三、匹配上1,2,3 三种字符串 四、匹配上第一个字符串 五、反向引用 反向引用还可以将通用资源指示符 (URI) 分解为其组件 举例&#xff1a;将下面的 URI 分解为协议&#xff08;ftp、http 等…

Stable Diffusion 图生图-蒙版重绘,Controlnet未生效的一个场景

首先感谢秋叶大佬的整合包&#xff01;&#xff01;&#xff01; 致敬所有在为AI绘画付出努力的大佬&#xff01;&#xff01;&#xff01; 省流&#xff1a;绘图时禁用插件sd-webui-segment-anything 场景&#xff1a;在电商换装场景下&#xff0c;为图中角色换衣服,使用了2个…

力扣 -- 198. 打家劫舍

题目链接&#xff1a;198. 打家劫舍 - 力扣&#xff08;LeetCode&#xff09; 在看这道题之前可以先看看按摩师的博文&#xff0c;写的细节更详细。(4条消息) 力扣 -- 面试题 17.16. 按摩师_高比拜仁0824的博客-CSDN博客 下面是用动态规划的思想解决这道题的过程&#xff0c…

MySQL:数据库的基本操作及数据库的三大数据类型

目录 一、创建数据库 二、删除数据库 三、查询数据 四、在数据库使用Linux命令 五、数据库的编码方式以及校验规则 1、查看MySQL支持的所有编码方式 2、查看某一种编码方式支持的所有校验规则 3、查看所有的编码方式和校验规则 4、查看本地数据库使用的编码方式和校验规…

-Xss / -XX:ThreadStackSize

-Xss / -XX:ThreadStackSize指定线程最大栈空间jdk1.4里默认的栈大小是256KBjdk1.5里默认的栈大小为1M这个参数直接会影响创建线程数量&#xff0c;值越小创建线程数越多&#xff1b; &#xff08;估算jvm进程的最大线程数&#xff09;这个参数直接决定了函数可调用的最大深度&…

【Docker】完整的搭建和发布过程

【Docker】完整的搭建和发布过程 【一】shell和ftp工具选择【二】安装Docker【1】查看系统的内核版本【2】yum更新到最新版本【3】安装Docker所需的依赖包【4】设置Docker的yum的源【5】查看仓库所有Docker版本【6】安装Docker【7】启动Docker并添加开机自启动【8】查看Docker版…

秋招提前批!大厂offer的捷径!

前言 又是一年秋招季&#xff01;年年岁岁花相似&#xff0c;岁岁年年人不同。 今天&#xff0c;博主在牛客上看到一个帖子&#xff0c;24届校招提前批已经开始了&#xff01; 24届大厂提前批 首先&#xff0c;跟大家科普一下提前批的概念&#xff0c;提前批是指企业在校园招…

TCP / IP 参考模型

TCP / IP 参考模型 5层参考模型5层参考模型5层模型的数据封装 5层参考模型 5层参考模型 综合 OSI 和 TCP/IP 的优点应用层: 支持各种网络应用 FTP, SMTP, HTTP 传输层: 进程-进程的数据传输 TCP, UDP 网络层: 源主机到目的主机的数据分组路由与转发 IP协议、路由协议等 链路层…

C语言入门篇(六)

前言   C 语言支持数组数据结构&#xff0c;数组是用来存储一系列数据&#xff0c;而且是一系列相同类型的变量。 数组 1. 一维数组1.1 数组的创建1.2 数组的初始化1.3 数组的使用1.4 数组在内存中的存储 2. 二维数组1.1 数组的创建1.2 数组的初始化1.3 数组的使用1.4 数组在…

23款奔驰GLS400升级柏林之声音响系统+HUD抬头显示系统

奔驰GLS400升级柏林之声的音响效果自然非同凡响&#xff0c;在人声、交响乐音乐厅感受方面都有非常逼真的现场感受&#xff0c;结合柏林之声的界面调整&#xff0c;可以在不同方位体验的高保真的音乐之享&#xff01; 强悍的显示效果&#xff0c;让您在动感中驾驭乐趣&#xff…

MinIO简单安装及使用

MinIO简介 MinIO是一个开源的、云原生的对象存储服务器&#xff0c;它提供了简单、高性能、安全、可扩展的存储服务。MinIO最初是作为一个Amazon S3兼容的对象存储服务器开发的&#xff0c;可以通过S3 API与其他应用程序和服务进行交互。MinIO支持分布式部署&#xff0c;可以在…