假期作业11

mental评估表:

点击查看代码
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>精神状态评估</title>
    <style>
        /* 全局样式 */
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background-color: #f9f9f9;
            color: #333;
            margin: 0;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
        }

        h1 {
            color: #007BFF;
            font-size: 28px;
            margin-bottom: 20px;
        }

        form {
            background-color: #fff;
            padding: 30px;
            border-radius: 8px;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            width: 100%;
            max-width: 600px;
            display: flex;
            flex-direction: column;
        }

        label {
            display: block;
            font-weight: 600;
            margin-bottom: 5px;
            color: #555;
        }

        input[type="text"],
        input[type="date"],
        input[type="number"],
        select {
            width: 100%;
            padding: 12px;
            margin-bottom: 20px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            font-size: 16px;
        }

        input[type="text"]:focus,
        input[type="date"]:focus,
        input[type="number"]:focus,
        select:focus {
            border-color: #007BFF;
            outline: none;
            box-shadow: 0 0 0 2px rgba(0, 123, 255, 0.25);
        }

        input[type="submit"] {
            background-color: #007BFF;
            color: white;
            padding: 12px 20px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 16px;
            transition: background-color 0.3s ease;
        }

        input[type="submit"]:hover {
            background-color: #0056b3;
        }

        #message {
            margin-top: 20px;
            padding: 10px;
            border-radius: 4px;
            text-align: center;
            font-size: 16px;
        }

        #message.success {
            background-color: #d4edda;
            color: #155724;
        }

        #message.error {
            background-color: #f8d7da;
            color: #721c24;
        }

        /* 响应式设计 */
        @media (max-width: 600px) {
            form {
                padding: 20px;
            }
        }
    </style>
</head>

<body>
<h1>精神状态评估</h1>
<form id="addMentalStateForm" action="${pageContext.request.contextPath}/addMentalServlet" method="post">
    <!-- 认知功能得分 -->
    <label for="cognitiveFunctionScore">认知功能得分:</label>
    <select id="cognitiveFunctionScore" name="cognitiveFunctionScore">
        <option value="0">0 分,画钟正确(画出一个闭锁圆,指针位置准确),且能回忆出 2 - 3 个词</option>
        <option value="1">1 分,画钟错误(画的圆不闭锁,或指针位置不准确),或只回忆出 0 - 1 个词</option>
        <option value="2">2 分,已确诊为认知障碍,如老年痴呆</option>
    </select>
    <!-- 攻击行为得分 -->
    <label for="aggressiveBehaviorScore">攻击行为得分:</label>
    <select id="aggressiveBehaviorScore" name="aggressiveBehaviorScore">
        <option value="0">0 分,无身体攻击行为(如打/踢/推/咬/抓/摔东西)和语言攻击行为(如骂人、语言威胁、尖叫)</option>
        <option value="1">1 分,每月有几次身体攻击行为,或每周有几次语言攻击行为</option>
        <option value="2">2 分,每周有几次身体攻击行为,或每日有语言攻击行为</option>
    </select>
    <!-- 抑郁症状得分 -->
    <label for="depressiveSymptomsScore">抑郁症状得分:</label>
    <select id="depressiveSymptomsScore" name="depressiveSymptomsScore">
        <option value="0">0 分,无</option>
        <option value="1">1 分,情绪低落、不爱说话、不爱梳洗、不爱活动</option>
        <option value="2">2 分,有自杀念头或自杀行为</option>
    </select>
    <input type="submit" value="提交">
</form>
<div id="message"></div>
</body>

</html>

pojo:

点击查看代码
package com.vivy.pojo;

public class Mental {

    private Integer id;
    private Integer cognitiveFunctionScore;
    private Integer aggressiveBehaviorScore;
    private Integer depressiveSymptomsScore;
    private Integer totalScore;
    private Integer mentalStateLevel;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCognitiveFunctionScore() {
        return cognitiveFunctionScore;
    }

    public void setCognitiveFunctionScore(Integer cognitiveFunctionScore) {
        this.cognitiveFunctionScore = cognitiveFunctionScore;
    }

    public Integer getAggressiveBehaviorScore() {
        return aggressiveBehaviorScore;
    }

    public void setAggressiveBehaviorScore(Integer aggressiveBehaviorScore) {
        this.aggressiveBehaviorScore = aggressiveBehaviorScore;
    }

    public Integer getDepressiveSymptomsScore() {
        return depressiveSymptomsScore;
    }

    public void setDepressiveSymptomsScore(Integer depressiveSymptomsScore) {
        this.depressiveSymptomsScore = depressiveSymptomsScore;
    }

    public Integer getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(Integer totalScore) {
        this.totalScore = totalScore;
    }

    public Integer getMentalStateLevel() {
        return mentalStateLevel;
    }

    public void setMentalStateLevel(Integer mentalStateLevel) {
        this.mentalStateLevel = mentalStateLevel;
    }

    @Override
    public String toString() {
        return "Mental{" +
                "id=" + id +
                ", cognitiveFunctionScore=" + cognitiveFunctionScore +
                ", aggressiveBehaviorScore=" + aggressiveBehaviorScore +
                ", depressiveSymptomsScore=" + depressiveSymptomsScore +
                ", totalScore=" + totalScore +
                ", mentalStateLevel=" + mentalStateLevel +
                '}';
    }
}

mapper:

点击查看代码
package com.vivy.mapper;

import com.vivy.pojo.Mental;


public interface MentalMapper {

    void add(Mental mental);

}

mapper.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.vivy.mapper.MentalMapper">


    <insert id="add" parameterType="com.vivy.pojo.Mental">
        INSERT INTO tb_mental (
            cognitiveFunctionScore,aggressiveBehaviorScore,depressiveSymptomsScore,
            totalScore,mentalStateLevel
        ) VALUES (
                     #{cognitiveFunctionScore}, #{aggressiveBehaviorScore}, #{depressiveSymptomsScore},
                     #{totalScore}, #{mentalStateLevel}
                 )
    </insert>

</mapper>

service:

点击查看代码
package com.vivy.service;

import com.vivy.mapper.MentalMapper;
import com.vivy.pojo.Mental;
import com.vivy.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

public class MentalService {
    SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();

    public void add(Mental mental){

        SqlSession sqlSession = sqlSessionFactory.openSession();
        MentalMapper mentalMapper = sqlSession.getMapper(MentalMapper.class);

        mentalMapper.add(mental);

        sqlSession.commit();
        sqlSession.close();
    }
}

posted @ 2025-02-20 19:20  vivi_vimi  阅读(15)  评论(0)    收藏  举报