寒假web开发6
表五: Communication
sql
点击查看代码
CREATE TABLE tb_communication (
AssessmentID CHAR(8) PRIMARY KEY, -- 评估编号(主键,关联到 tb_older 表的 AssessmentID)
-- B.3.1 意识水平
consciousnessLevel INT , -- 意识水平评分
-- 0: 神志清醒, 1: 嗜睡, 2: 昏睡, 3: 昏迷
-- B.3.2 视力
visionLevel INT, -- 视力评分
-- 0: 能看清书报上的标准字体, 1: 能看清楚大字体, 2: 视力有限, 3: 辨认物体有困难, 4: 没有视力
-- B.3.3 听力
hearingLevel INT , -- 听力评分
-- 0: 可正常交谈, 1: 轻声说话或距离超过2米时听不清, 2: 正常交流有些困难, 3: 大声说话才能部分听见, 4: 完全听不见
-- B.3.4 沟通交流
communicationLevel INT , -- 沟通交流评分
-- 0: 无困难, 1: 需要增加时间或帮助, 2: 表达或理解有困难, 3: 不能表达或理解
-- B.3 感知觉与沟通分级
overallGrade INT -- 总分级
-- 0: 能力完好, 1: 轻度受损, 2: 中度受损, 3: 重度受损
);
CommunicationMapper
点击查看代码
package com.QixunQiu.mapper;
import com.QixunQiu.pojo.Communication;
import com.QixunQiu.pojo.Daily;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import java.util.List;
public interface CommunicationMapper {
@Select("select * from tb_communication where AssessmentID = #{AssessmentID} ")
List<Communication> select(@Param("AssessmentID") String AssessmentID);
void addCommunication(Communication communication);
}
Communication的pojo
点击查看代码
package com.QixunQiu.pojo;
public class Communication {
private String assessmentID; // 评估编号
private Integer consciousnessLevel; // 意识水平评分
private Integer visionLevel; // 视力评分
private Integer hearingLevel; // 听力评分
private Integer communicationLevel; // 沟通交流评分
private Integer overallGrade; // 总分级
@Override
public String toString() {
return "Communication{" +
"assessmentID='" + assessmentID + '\'' +
", consciousnessLevel=" + consciousnessLevel +
", visionLevel=" + visionLevel +
", hearingLevel=" + hearingLevel +
", communicationLevel=" + communicationLevel +
", overallGrade=" + overallGrade +
'}';
}
// Getters and Setters
public String getAssessmentID() {
return assessmentID;
}
public void setAssessmentID(String assessmentID) {
this.assessmentID = assessmentID;
}
public Integer getConsciousnessLevel() {
return consciousnessLevel;
}
public void setConsciousnessLevel(Integer consciousnessLevel) {
this.consciousnessLevel = consciousnessLevel;
}
public Integer getVisionLevel() {
return visionLevel;
}
public void setVisionLevel(Integer visionLevel) {
this.visionLevel = visionLevel;
}
public Integer getHearingLevel() {
return hearingLevel;
}
public void setHearingLevel(Integer hearingLevel) {
this.hearingLevel = hearingLevel;
}
public Integer getCommunicationLevel() {
return communicationLevel;
}
public void setCommunicationLevel(Integer communicationLevel) {
this.communicationLevel = communicationLevel;
}
public Integer getOverallGrade() {
return overallGrade;
}
public void setOverallGrade(Integer overallGrade) {
this.overallGrade = overallGrade;
}
}
CommunicationService
点击查看代码
package com.QixunQiu.service;
import com.QixunQiu.mapper.CommunicationMapper;
import com.QixunQiu.pojo.Communication;
import com.QixunQiu.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import java.util.List;
public class CommunicationService {
SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
public List<Communication> select(String AssessmentID) {
SqlSession sqlSession = sqlSessionFactory.openSession();
CommunicationMapper communicationMapper = sqlSession.getMapper(CommunicationMapper.class);
List<Communication> communicationList=communicationMapper.select(AssessmentID);
sqlSession.close();
return communicationList;
}
public void add(Communication communication) {
SqlSession sqlSession = sqlSessionFactory.openSession();
CommunicationMapper communicationMapper = sqlSession.getMapper(CommunicationMapper.class);
communicationMapper.addCommunication(communication);
sqlSession.commit();
sqlSession.close();
}
}
AddCommunicationServlet
点击查看代码
package com.QixunQiu.web;
import com.QixunQiu.pojo.Communication;
import com.QixunQiu.service.CommunicationService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
@WebServlet("/AddCommunicationServlet")
public class AddCommunicationServlet extends HttpServlet {
private CommunicationService communicationService = new CommunicationService();
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
String assessmentID=request.getParameter("assessmentID");
int consciousnessLevel=Integer.parseInt(request.getParameter("consciousnessLevel"));
int visionLevel=Integer.parseInt(request.getParameter("visionLevel"));
int hearingLevel=Integer.parseInt(request.getParameter("hearingLevel"));
int communicationLevel=Integer.parseInt(request.getParameter("communicationLevel"));
int overallGrade;
if (consciousnessLevel == 0 && visionLevel <= 1 && hearingLevel <= 1 && communicationLevel == 0) {
overallGrade = 0;
} else if (consciousnessLevel == 0 && (visionLevel == 2 || hearingLevel == 2) || communicationLevel == 1) {
overallGrade = 1;
} else if ((consciousnessLevel == 0 && (visionLevel == 3 || hearingLevel == 3) || communicationLevel == 2) ||
(consciousnessLevel == 1 && visionLevel <= 3 && hearingLevel <= 3 && communicationLevel <= 2)) {
overallGrade= 2;
} else {
overallGrade= 3;
}
Communication communication = new Communication();
communication.setAssessmentID(assessmentID);
communication.setConsciousnessLevel(consciousnessLevel);
communication.setVisionLevel(visionLevel);
communication.setHearingLevel(hearingLevel);
communication.setCommunicationLevel(communicationLevel);
communication.setOverallGrade(overallGrade);
communicationService.add(communication);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
selectCommunicationServlet
点击查看代码
package com.QixunQiu.web;
import com.QixunQiu.pojo.Communication;
import com.QixunQiu.pojo.Daily;
import com.QixunQiu.pojo.Older;
import com.QixunQiu.pojo.User;
import com.QixunQiu.service.CommunicationService;
import com.QixunQiu.service.OlderService;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
@WebServlet("/selectCommunicationServlet")
public class selectCommunicationServlet extends HttpServlet {
private OlderService olderService = new OlderService();
private CommunicationService communicationService = new CommunicationService();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
Older older=olderService.selectOlderById(user.getUserID());
List<Communication> communicationList=communicationService.select(older.getAssessmentID());
PrintWriter writer = response.getWriter();
if(!communicationList.isEmpty()){
// 登陆成功
writer.write("登陆成功");
System.out.println(communicationList);
session.setAttribute("communicationList", communicationList);
request.getRequestDispatcher("/communication.jsp").forward(request,response);
}else {
// 登陆失败
writer.write("登陆失败");
request.getRequestDispatcher("/addCommunication.jsp").forward(request,response);
}
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
}
}
CommunicationMapper.xml
点击查看代码
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.QixunQiu.mapper.CommunicationMapper">
<insert id="addCommunication">
INSERT INTO tb_communication (
AssessmentID,
consciousnessLevel,
visionLevel,
hearingLevel,
communicationLevel,
overallGrade
)
VALUES (
#{assessmentID},
#{consciousnessLevel},
#{visionLevel},
#{hearingLevel},
#{communicationLevel},
#{overallGrade}
)
</insert>
</mapper>
addCommunication.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>添加感知觉与沟通评估</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
margin: 0;
padding: 0;
}
.container {
width: 50%;
margin: 50px auto;
background: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
h2 {
text-align: center;
color: #333;
}
label {
display: block;
margin: 10px 0 5px;
color: #555;
}
input[type="text"], input[type="number"], select {
width: 100%;
padding: 8px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="submit"] {
width: 100%;
padding: 10px;
background-color: #28a745;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
}
input[type="submit"]:hover {
background-color: #218838;
}
</style>
</head>
<body>
<div class="container">
<h2>添加感知觉与沟通评估</h2>
<form action="${pageContext.request.contextPath}/AddCommunicationServlet" method="post">
<label for="assessmentID">评估编号:</label>
<input type="text" id="assessmentID" name="assessmentID" required>
<label for="consciousnessLevel">意识水平评分:</label>
<select id="consciousnessLevel" name="consciousnessLevel" required>
<option value="0">0: 神志清醒</option>
<option value="1">1: 嗜睡</option>
<option value="2">2: 昏睡</option>
<option value="3">3: 昏迷</option>
</select>
<label for="visionLevel">视力评分:</label>
<select id="visionLevel" name="visionLevel" required>
<option value="0">0: 能看清书报上的标准字体</option>
<option value="1">1: 能看清楚大字体</option>
<option value="2">2: 视力有限</option>
<option value="3">3: 辨认物体有困难</option>
<option value="4">4: 没有视力</option>
</select>
<label for="hearingLevel">听力评分:</label>
<select id="hearingLevel" name="hearingLevel" required>
<option value="0">0: 可正常交谈</option>
<option value="1">1: 轻声说话或距离超过2米时听不清</option>
<option value="2">2: 正常交流有些困难</option>
<option value="3">3: 大声说话才能部分听见</option>
<option value="4">4: 完全听不见</option>
</select>
<label for="communicationLevel">沟通交流评分:</label>
<select id="communicationLevel" name="communicationLevel" required>
<option value="0">0: 无困难</option>
<option value="1">1: 需要增加时间或帮助</option>
<option value="2">2: 表达或理解有困难</option>
<option value="3">3: 不能表达或理解</option>
</select>
<input type="submit" value="提交">
</form>
</div>
</body>
</html>
communication.jsp
点击查看代码
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>感知觉与沟通评估列表</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
h1 {
text-align: center;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
table, th, td {
border: 1px solid #ddd;
}
th, td {
padding: 10px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
tr:hover {
background-color: #f5f5f5;
}
</style>
</head>
<body>
<h1>感知觉与沟通评估列表</h1>
<table>
<thead>
<tr>
<th>评估编号</th>
<th>意识水平</th>
<th>视力评分</th>
<th>听力评分</th>
<th>沟通交流评分</th>
<th>总分级</th>
</tr>
</thead>
<tbody>
<c:forEach var="assessment" items="${communicationList}">
<tr>
<td>${assessment.assessmentID}</td>
<td>
<c:choose>
<c:when test="${assessment.consciousnessLevel == 0}">0 - 神志清醒</c:when>
<c:when test="${assessment.consciousnessLevel == 1}">1 - 嗜睡</c:when>
<c:when test="${assessment.consciousnessLevel == 2}">2 - 昏睡</c:when>
<c:when test="${assessment.consciousnessLevel == 3}">3 - 昏迷</c:when>
<c:otherwise>未知</c:otherwise>
</c:choose>
</td>
<td>
<c:choose>
<c:when test="${assessment.visionLevel == 0}">0 - 能看清书报上的标准字体</c:when>
<c:when test="${assessment.visionLevel == 1}">1 - 能看清楚大字体</c:when>
<c:when test="${assessment.visionLevel == 2}">2 - 视力有限</c:when>
<c:when test="${assessment.visionLevel == 3}">3 - 辨认物体有困难</c:when>
<c:when test="${assessment.visionLevel == 4}">4 - 没有视力</c:when>
<c:otherwise>未知</c:otherwise>
</c:choose>
</td>
<td>
<c:choose>
<c:when test="${assessment.hearingLevel == 0}">0 - 可正常交谈</c:when>
<c:when test="${assessment.hearingLevel == 1}">1 - 轻声说话或距离超过2米时听不清</c:when>
<c:when test="${assessment.hearingLevel == 2}">2 - 正常交流有些困难</c:when>
<c:when test="${assessment.hearingLevel == 3}">3 - 大声说话才能部分听见</c:when>
<c:when test="${assessment.hearingLevel == 4}">4 - 完全听不见</c:when>
<c:otherwise>未知</c:otherwise>
</c:choose>
</td>
<td>
<c:choose>
<c:when test="${assessment.communicationLevel == 0}">0 - 无困难</c:when>
<c:when test="${assessment.communicationLevel == 1}">1 - 需要增加时间或帮助</c:when>
<c:when test="${assessment.communicationLevel == 2}">2 - 表达或理解有困难</c:when>
<c:when test="${assessment.communicationLevel == 3}">3 - 不能表达或理解</c:when>
<c:otherwise>未知</c:otherwise>
</c:choose>
</td>
<td>
<c:choose>
<c:when test="${assessment.overallGrade == 0}">0 - 能力完好</c:when>
<c:when test="${assessment.overallGrade == 1}">1 - 轻度受损</c:when>
<c:when test="${assessment.overallGrade == 2}">2 - 中度受损</c:when>
<c:when test="${assessment.overallGrade == 3}">3 - 重度受损</c:when>
<c:otherwise>未知</c:otherwise>
</c:choose>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· DeepSeek在M芯片Mac上本地化部署
· 葡萄城 AI 搜索升级:DeepSeek 加持,客户体验更智能