Update README.md

pull/2/head
hql 4 months ago
parent f7029491da
commit 87bec144e2

@ -11,7 +11,7 @@
<component name="ChangeListManager">
<list default="true" id="0ffa26fe-3275-4667-90ad-c688ca600b30" name="Default Changelist" comment="&#10;Update README.md">
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/controller/deptadmin/DeptAddStuServlet.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/controller/deptadmin/DeptAddStuServlet.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/controller/deptadmin/DeptAddTeaPunchServlet.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/controller/deptadmin/DeptAddTeaPunchServlet.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -360,7 +360,7 @@
<workItem from="1745045574258" duration="638000" />
<workItem from="1745046236628" duration="3804000" />
<workItem from="1745050261322" duration="1665000" />
<workItem from="1745132180317" duration="2942000" />
<workItem from="1745132180317" duration="3390000" />
</task>
<task id="LOCAL-00001" summary="Update README.md">
<option name="closed" value="true" />
@ -450,7 +450,15 @@
<option name="project" value="LOCAL" />
<updated>1745135002854</updated>
</task>
<option name="localTasksCounter" value="12" />
<task id="LOCAL-00012" summary="&#10;Update README.md">
<option name="closed" value="true" />
<created>1745135472858</created>
<option name="number" value="00012" />
<option name="presentableId" value="LOCAL-00012" />
<option name="project" value="LOCAL" />
<updated>1745135472858</updated>
</task>
<option name="localTasksCounter" value="13" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">

@ -1,6 +1,6 @@
package com.controller.deptadmin;
package com.controller.deptadmin;//包声明类位于com.controller.deptadmin包中归类管理部门相关的控制器。
import com.dao.DeptAdminDao;
import com.dao.DeptAdminDao;//包声明类位于com.controller.deptadmin包中归类管理部门相关的控制器。
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
@ -9,51 +9,52 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/DeptAddTeaPunchServlet")
@WebServlet("/DeptAddTeaPunchServlet")//Servlet注解与类定义映射URL路径/DeptAddTeaPunchServlet继承HttpServlet处理HTTP请求。
public class DeptAddTeaPunchServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {//处理GET请求重写doGet方法处理HTTP GET请求。
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
//获取表单请求的参数
String tno = req.getParameter("tno");
String tispunch = req.getParameter("tispunch");
String tpunchdate = req.getParameter("tpunchdate");
String tpunchtime = req.getParameter("tpunchtime");
String tishot = req.getParameter("tishot");
String tiscough = req.getParameter("tiscough");
String tisseem = req.getParameter("tisseem");
String tisdiagnose = req.getParameter("tisdiagnose");
String tstatus = req.getParameter("tstatus");
resp.setContentType("text/html;charset=utf-8");//统一请求和响应的字符编码为UTF-8防止中文乱码并设置响应内容类型为HTML
//使用 req.getParameter("parameterName") 获取前端表单提交的每个参数的值
String tno = req.getParameter("tno");//教师编号
String tispunch = req.getParameter("tispunch");//是否打卡
String tpunchdate = req.getParameter("tpunchdate");//打卡日期
String tpunchtime = req.getParameter("tpunchtime");//打卡时间
String tishot = req.getParameter("tishot");//是否发热
String tiscough = req.getParameter("tiscough");//是否咳嗽
String tisseem = req.getParameter("tisseem");//是否见过人
String tisdiagnose = req.getParameter("tisdiagnose");//是否诊断
String tstatus = req.getParameter("tstatus");//状态
String sql = null;
System.out.println("shgshgh");
System.out.println("shgshgh");//这行代码是一个调试语句,打印 "shgshgh" 到控制台。它通常用于开发调试阶段,帮助开发者跟踪程序执行情况。可以在正式环境中移除。
//查询是否已打卡
sql = "select count(*) as num from teapunchin where tno = ? and tpunchdate = ?";
Object[] objects = {tno, tpunchdate};
int count = DeptAdminDao.findTotalCount(sql, objects);
Object[] objects = {tno, tpunchdate};//构造一个 SQL 查询语句检查数据库中是否已经存在该教师tno在指定日期tpunchdate的打卡记录。
int count = DeptAdminDao.findTotalCount(sql, objects);//使用 DeptAdminDao.findTotalCount() 方法执行查询并返回匹配的记录数。count 表示查询结果,判断是否已有相同的打卡记录。
if (count == 0){//无则操作
if (count == 0){//如果查询结果 count 为 0表示该教师在该日期没有打卡记录因此可以插入新的打卡记录。
sql = "insert into teapunchin values(?, ?, ?, ?, ?, ?, ?, ?, ?)";
Object[] objects1 = {tno, tispunch, tpunchdate, tpunchtime, tishot, tiscough, tisseem, tisdiagnose, tstatus};
//构造 SQL 插入语句,将教师的打卡信息插入到 teapunchin 表中。插入的字段包括:教师编号、是否打卡、打卡日期、打卡时间、是否发热、是否咳嗽、是否见过人、是否诊断、状态。
int num = DeptAdminDao.executeUpdate(sql, objects1);
int num = DeptAdminDao.executeUpdate(sql, objects1);//使用 DeptAdminDao.executeUpdate() 方法执行插入操作,返回受影响的行数(即成功插入的记录数)。将插入操作的结果存储在 num 变量中。
System.out.println(num);
System.out.println(num);//在控制台打印 num用来调试输出插入操作是否成功通常用于开发过程中查看插入操作是否成功。
req.getRequestDispatcher("/DeptQueryTeaPunchByPageServlet?currentPage=1&rows=7&tno=&tname=&tpunchdate=").forward(req, resp);
}else {
}else {//如果插入操作成功,使用 req.getRequestDispatcher().forward() 方法将请求转发到另一个 Servlet (DeptQueryTeaPunchByPageServlet),用于分页查询教师的打卡记录。
req.getRequestDispatcher("/view/alluse/existdataofadd.jsp").forward(req, resp);
}
} //如果查询到已经存在相同的打卡记录count > 0则转发请求到 existdataofadd.jsp 页面,提示用户该打卡记录已存在,无法再次添加。
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
doGet(req, resp);//doPost 方法处理 HTTP POST 请求。此处doPost 方法调用 doGet 方法,使得 POST 请求和 GET 请求的处理逻辑一致,避免重复代码。
}
}

Loading…
Cancel
Save