基于 JAVASSM(Java + Spring + Spring MVC + MyBatis)框架开发一个医院挂号系统
基于 JAVASSM(Java + Spring + Spring MVC + MyBatis)框架开发一个医院挂号系统是一个实用的项目。

步骤一:需求分析
明确系统需要实现的功能,比如:
- 用户注册和登录
- 查看医生列表
- 预约挂号
- 查看预约记录
- 取消预约
- 管理员管理医生信息和预约记录
步骤二:设计数据库
使用 MySQL 数据库存储系统数据。设计数据库表结构如下:
用户表(users)
- id (INT, 主键, 自增)
- username (VARCHAR)
- password (VARCHAR)
- email (VARCHAR)
- phone (VARCHAR)
医生表(doctors)
- id (INT, 主键, 自增)
- name (VARCHAR)
- department (VARCHAR)
- introduction (TEXT)
- schedule (TEXT)
预约表(appointments)
- id (INT, 主键, 自增)
- user_id (INT, 外键)
- doctor_id (INT, 外键)
- appointment_time (DATETIME)
- status (VARCHAR)
步骤三:选择开发工具
使用 IntelliJ IDEA 或 Eclipse 作为开发环境。
步骤四:搭建项目结构
- 创建 Maven 项目。
- 添加必要的依赖项(Spring、Spring MVC、MyBatis、MySQL 驱动等)。
步骤五:配置文件
application.properties
spring.datasource.url=jdbc:mysql://localhost:3306/hospital_registration?useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Drivermybatis.mapper-locations=classpath:mapper/*.xml
spring-mvc.xml
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:mvc="http://www.springframework.org/schema/mvc"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsd"><context:component-scan base-package="com.hospital"/><mvc:annotation-driven/><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/views/"/><property name="suffix" value=".jsp"/></bean></beans>
mybatis-config.xml
<configuration><mappers><mapper resource="mapper/UserMapper.xml"/><mapper resource="mapper/DoctorMapper.xml"/><mapper resource="mapper/AppointmentMapper.xml"/></mappers>
</configuration>
步骤六:编写实体类
User.java
package com.hospital.entity;public class User {private int id;private String username;private String password;private String email;private String phone;// Getters and Setters
}
Doctor.java
package com.hospital.entity;public class Doctor {private int id;private String name;private String department;private String introduction;private String schedule;// Getters and Setters
}
Appointment.java
package com.hospital.entity;import java.util.Date;public class Appointment {private int id;private int userId;private int doctorId;private Date appointmentTime;private String status;// Getters and Setters
}
步骤七:编写 DAO 层
UserMapper.java
package com.hospital.mapper;import com.hospital.entity.User;
import org.apache.ibatis.annotations.*;@Mapper
public interface UserMapper {@Select("SELECT * FROM users WHERE username = #{username} AND password = #{password}")User login(@Param("username") String username, @Param("password") String password);@Insert("INSERT INTO users(username, password, email, phone) VALUES(#{username}, #{password}, #{email}, #{phone})")@Options(useGeneratedKeys = true, keyProperty = "id")void register(User user);
}
DoctorMapper.java
package com.hospital.mapper;import com.hospital.entity.Doctor;
import org.apache.ibatis.annotations.*;import java.util.List;@Mapper
public interface DoctorMapper {@Select("SELECT * FROM doctors")List<Doctor> getAllDoctors();@Select("SELECT * FROM doctors WHERE id = #{id}")Doctor getDoctorById(int id);@Insert("INSERT INTO doctors(name, department, introduction, schedule) VALUES(#{name}, #{department}, #{introduction}, #{schedule})")@Options(useGeneratedKeys = true, keyProperty = "id")void addDoctor(Doctor doctor);@Update("UPDATE doctors SET name=#{name}, department=#{department}, introduction=#{introduction}, schedule=#{schedule} WHERE id=#{id}")void updateDoctor(Doctor doctor);@Delete("DELETE FROM doctors WHERE id=#{id}")void deleteDoctor(int id);
}
AppointmentMapper.java
package com.hospital.mapper;import com.hospital.entity.Appointment;
import org.apache.ibatis.annotations.*;import java.util.List;@Mapper
public interface AppointmentMapper {@Select("SELECT * FROM appointments WHERE user_id = #{userId}")List<Appointment> getAppointmentsByUserId(int userId);@Select("SELECT * FROM appointments WHERE id = #{id}")Appointment getAppointmentById(int id);@Insert("INSERT INTO appointments(user_id, doctor_id, appointment_time, status) VALUES(#{userId}, #{doctorId}, #{appointmentTime}, #{status})")@Options(useGeneratedKeys = true, keyProperty = "id")void addAppointment(Appointment appointment);@Update("UPDATE appointments SET appointment_time=#{appointmentTime}, status=#{status} WHERE id=#{id}")void updateAppointment(Appointment appointment);@Delete("DELETE FROM appointments WHERE id=#{id}")void deleteAppointment(int id);
}
步骤八:编写 Service 层
UserService.java
package com.hospital.service;import com.hospital.entity.User;
import com.hospital.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;@Service
public class UserService {@Autowiredprivate UserMapper userMapper;public User login(String username, String password) {return userMapper.login(username, password);}public void register(User user) {userMapper.register(user);}
}
DoctorService.java
package com.hospital.service;import com.hospital.entity.Doctor;
import com.hospital.mapper.DoctorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class DoctorService {@Autowiredprivate DoctorMapper doctorMapper;public List<Doctor> getAllDoctors() {return doctorMapper.getAllDoctors();}public Doctor getDoctorById(int id) {return doctorMapper.getDoctorById(id);}public void addDoctor(Doctor doctor) {doctorMapper.addDoctor(doctor);}public void updateDoctor(Doctor doctor) {doctorMapper.updateDoctor(doctor);}public void deleteDoctor(int id) {doctorMapper.deleteDoctor(id);}
}
AppointmentService.java
package com.hospital.service;import com.hospital.entity.Appointment;
import com.hospital.mapper.AppointmentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;import java.util.List;@Service
public class AppointmentService {@Autowiredprivate AppointmentMapper appointmentMapper;public List<Appointment> getAppointmentsByUserId(int userId) {return appointmentMapper.getAppointmentsByUserId(userId);}public Appointment getAppointmentById(int id) {return appointmentMapper.getAppointmentById(id);}public void addAppointment(Appointment appointment) {appointmentMapper.addAppointment(appointment);}public void updateAppointment(Appointment appointment) {appointmentMapper.updateAppointment(appointment);}public void deleteAppointment(int id) {appointmentMapper.deleteAppointment(id);}
}
步骤九:编写 Controller 层
UserController.java
package com.hospital.controller;import com.hospital.entity.User;
import com.hospital.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;@Controller
public class UserController {@Autowiredprivate UserService userService;@GetMapping("/login")public String showLoginForm() {return "login";}@PostMapping("/login")public String handleLogin(@RequestParam("username") String username, @RequestParam("password") String password, Model model) {User user = userService.login(username, password);if (user != null) {model.addAttribute("user", user);return "redirect:/doctors";} else {model.addAttribute("error", "Invalid username or password");return "login";}}@GetMapping("/register")public String showRegisterForm() {return "register";}@PostMapping("/register")public String handleRegister(User user) {userService.register(user);return "redirect:/login";}
}
DoctorController.java
package com.hospital.controller;import com.hospital.entity.Doctor;
import com.hospital.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;import java.util.List;@Controller
public class DoctorController {@Autowiredprivate DoctorService doctorService;@GetMapping("/doctors")public String showDoctors(Model model) {List<Doctor> doctors = doctorService.getAllDoctors();model.addAttribute("doctors", doctors);return "doctors";}@GetMapping("/doctor/{id}")public String showDoctorDetails(@RequestParam("id") int id, Model model) {Doctor doctor = doctorService.getDoctorById(id);model.addAttribute("doctor", doctor);return "doctorDetails";}@GetMapping("/addDoctor")public String showAddDoctorForm() {return "addDoctor";}@PostMapping("/addDoctor")public String handleAddDoctor(Doctor doctor) {doctorService.addDoctor(doctor);return "redirect:/doctors";}@GetMapping("/editDoctor/{id}")public String showEditDoctorForm(@RequestParam("id") int id, Model model) {Doctor doctor = doctorService.getDoctorById(id);model.addAttribute("doctor", doctor);return "editDoctor";}@PostMapping("/editDoctor")public String handleEditDoctor(Doctor doctor) {doctorService.updateDoctor(doctor);return "redirect:/doctors";}@GetMapping("/deleteDoctor/{id}")public String handleDeleteDoctor(@RequestParam("id") int id) {doctorService.deleteDoctor(id);return "redirect:/doctors";}
}
AppointmentController.java
package com.hospital.controller;import com.hospital.entity.Appointment;
import com.hospital.entity.Doctor;
import com.hospital.service.AppointmentService;
import com.hospital.service.DoctorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;import java.util.Date;
import java.util.List;@Controller
public class AppointmentController {@Autowiredprivate AppointmentService appointmentService;@Autowiredprivate DoctorService doctorService;@GetMapping("/appointments")public String showAppointments(@RequestParam("userId") int userId, Model model) {List<Appointment> appointments = appointmentService.getAppointmentsByUserId(userId);model.addAttribute("appointments", appointments);return "appointments";}@GetMapping("/makeAppointment")public String showMakeAppointmentForm(@RequestParam("userId") int userId, Model model) {List<Doctor> doctors = doctorService.getAllDoctors();model.addAttribute("doctors", doctors);model.addAttribute("userId", userId);return "makeAppointment";}@PostMapping("/makeAppointment")public String handleMakeAppointment(@RequestParam("userId") int userId, @RequestParam("doctorId") int doctorId,@RequestParam("appointmentTime") String appointmentTime) {Appointment appointment = new Appointment();appointment.setUserId(userId);appointment.setDoctorId(doctorId);appointment.setAppointmentTime(new Date());appointment.setStatus("Pending");appointmentService.addAppointment(appointment);return "redirect:/appointments?userId=" + userId;}@GetMapping("/cancelAppointment/{id}")public String handleCancelAppointment(@RequestParam("id") int id, @RequestParam("userId") int userId) {appointmentService.deleteAppointment(id);return "redirect:/appointments?userId=" + userId;}
}
步骤十:前端页面
使用 JSP 创建前端页面。以下是简单的 JSP 示例:
login.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>Login</title>
</head>
<body>
<h2>Login</h2>
<form action="${pageContext.request.contextPath}/login" method="post">Username: <input type="text" name="username"><br>Password: <input type="password" name="password"><br><input type="submit" value="Login">
</form>
<c:if test="${not empty error}"><p style="color: red">${error}</p>
</c:if>
</body>
</html>
doctors.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head><title>Doctors</title>
</head>
<body>
<h2>Doctors</h2>
<table><tr><th>Name</th><th>Department</th><th>Introduction</th><th>Schedule</th><th>Action</th></tr><c:forEach items="${doctors}" var="doctor"><tr><td>${doctor.name}</td><td>${doctor.department}</td><td>${doctor.introduction}</td><td>${doctor.schedule}</td><td><a href="${pageContext.request.contextPath}/doctor/${doctor.id}">View</a><a href="${pageContext.request.contextPath}/editDoctor/${doctor.id}">Edit</a><a href="${pageContext.request.contextPath}/deleteDoctor/${doctor.id}">Delete</a></td></tr></c:forEach>
</table>
<a href="${pageContext.request.contextPath}/addDoctor">Add New Doctor</a>
</body>
</html>
makeAppointment.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head><title>Make Appointment</title>
</head>
<body>
<h2>Make Appointment</h2>
<form action="${pageContext.request.contextPath}/makeAppointment" method="post"><input type="hidden" name="userId" value="${userId}">Doctor:<select name="doctorId"><c:forEach items="${doctors}" var="doctor"><option value="${doctor.id}">${doctor.name} (${doctor.department})</option></c:forEach></select><br>Appointment Time: <input type="datetime-local" name="appointmentTime"><br><input type="submit" value="Make Appointment">
</form>
</body>
</html>
步骤十一:测试与调试
对每个功能进行详细测试,确保所有功能都能正常工作。
步骤十二:部署与发布
编译最终版本的应用程序,并准备好 WAR 文件供 Tomcat 或其他应用服务器部署。
相关文章:
基于 JAVASSM(Java + Spring + Spring MVC + MyBatis)框架开发一个医院挂号系统
基于 JAVASSM(Java Spring Spring MVC MyBatis)框架开发一个医院挂号系统是一个实用的项目。 步骤一:需求分析 明确系统需要实现的功能,比如: 用户注册和登录查看医生列表预约挂号查看预约记录取消预约管理员管…...
Golang | Leetcode Golang题解之第540题有序数组中的单一元素
题目: 题解: func singleNonDuplicate(nums []int) int {low, high : 0, len(nums)-1for low < high {mid : low (high-low)/2mid - mid & 1if nums[mid] nums[mid1] {low mid 2} else {high mid}}return nums[low] }...
影刀RPA实战:嵌入python,如虎添翼
1. 影刀RPA与Python的关系 影刀RPA与Python的关系可以从以下几个方面来理解: 技术互补:影刀RPA是一种自动化工具,它允许用户通过图形化界面创建自动化流程,而Python是一种编程语言,常用于编写自动化脚本。影刀RPA可以…...
es 数据清理delete_by_query
POST /索引名/_delete_by_query?conflictsproceed&scroll_size2000&wait_for_completionfalse&slices36 {"size": 2000, "query": {"bool": { "must": [{"terms": {"rule_id": [800007]}}]}} }slice…...
【每日 C/C++ 问题】
一、C 中类的三大特性是什么?请简要解释。 封装、继承、多态 封装:将事物的属性(成员变量)和行为(成员函数)封装在一起形成一个类。并且可以设置相应的访问权限(私有的 受保护的 公有的&#…...
stm32学习4
学习目录 一.流水灯1.创建文件2.编写相关代码 一.流水灯 1.创建文件 将方法进行分类保存在不同的 .c 文件中,方便复用和寻找; 创建Hardware\LED文件,其中有led.c和led.h文件,用于存放有关LED灯操作的方法; 在User文…...
Midjourney国内直登
Midjourney确实是一个强大的AI绘画工具,能够根据用户输入的文本生成高质量的图像。然而,由于国内的网络限制,直接访问Midjourney可能会遇到障碍。 目前,已经有一些国内代理或中转平台可以帮助用户更方便地使用Midjourney…...
【双目视觉标定】——3面结构光相机标定实践(获取相机内参)~未完待续
相机标定基本原理及双目相机内参解析 相机标定是计算机视觉中的一个重要步骤,旨在确定相机的内部和外部参数,以便在图像处理中进行准确的三维重建、物体识别等任务。本文将重点讲解双目相机的内参和外参原理,并结合实际参数进行分析。 一、…...
Python常用脚本集锦
收集了一些常用Python脚本,作为平时练手使用,也可以作为自己的笔记,用到哪个功能可以自己查询一下即可。 文件和目录管理 复制文件 import shutil# 复制源文件到目标文件 shutil.copy(source.txt, destination.txt)移动文件 import shuti…...
MacBook 如何设置打开json格式文件的默认程序是vs code
首先右键选中文件,然后选中显示简介 然后选中打开方式 设置成vs code...
如何在 Spring Boot 中实现多数据源的事务管理?
在 Spring Boot 中实现多数据源的事务管理可以通过以下几种方式: 一、使用编程式事务管理 配置多个数据源 如同前面提到的,在 application.properties 或 application.yml 文件中配置多个数据源的连接信息,并创建对应的数据源 bean。 手动开启…...
SQL 常用更新操作
目录 1. 从一个查询结果中获取数据批量更新一张表 1. 从一个查询结果中获取数据批量更新一张表 更新table_a中所有id在tmp查询结果中的name值 UPDATE table_a a SET a.name tmp.name FROM (SELECT id, name FROM table_b) tmp WHERE a.id tmp.id;UPDATE table_a a JOIN (SE…...
Android camera2
一、序言 为了对阶段性的知识积累、方便以后调查问题,特做此文档! 将以camera app 使用camera2 api进行分析。 (1)、打开相机 openCamera (2)、创建会话 createCaptureSession (3)、开始预览 setRepeatingRequest (4)、停止预览 stopRepeating (5)、关闭…...
nginx监控指标有哪些
Nginx 的监控指标可以帮助你了解服务器的性能、资源使用以及运行状态。下面是一些常见的 Nginx 监控指标,涵盖了访问、性能、资源使用等多个方面: 1. 访问量与请求处理 Active Connections(活跃连接数):当前 Nginx 处…...
我谈正态分布——正态偏态
目录 pdf和cdf参数 标准正态分布期望和方差分布形态 3 σ 3\sigma 3σ原则 正态和偏态正态偏态瑞利分布偏度 (Skewness)峰度 (Kurtosis) 比较 正态分布的英文是Normal Distribution,normal是“正常”或“标准”的意思,中文翻译是正态,多完美的…...
如何使用uniswap v2 获取两个代币的交易对池子
在 Uniswap V2 中,获取两个代币的交易对池子(即 pair)可以通过以下步骤实现: 连接到 Uniswap V2 的合约:你需要与 Uniswap V2 的 Factory 合约进行交互,通过该合约来查找代币交易对。 获取交易对地址:Uniswap V2 Factory 合约提供了一个 getPair 函数,可以通过该函数查…...
CSS中常见的两列布局、三列布局、百分比和多行多列布局!
目录 一、两列布局 1、前言: 2. 两列布局的常见用法 两列布局的元素示例: 代码运行后如下: 二、三列布局 1.前言 2. 三列布局的常见用法 三列布局的元素示例: 代码运行后如下: 三、多行多列 1.前言 2&…...
GaussDB Ustore存储引擎解读
目录 一、数据库存储引擎 二、GaussDB Ustore存储引擎 总结 本文将介绍GaussDB中的Ustore存储引擎,包括Ustore的设计背景、特点介绍和适用业务场景等。 一、数据库存储引擎 数据库的存储引擎负责在内存和磁盘上存储、检索和管理数据,确保每个节点的…...
JAVA基础:数组 (习题笔记)
一,编码题 1,数组查找操作:定义一个长度为10 的一维字符串数组,在每一个元素存放一个单词;然后运行时从命令行输入一个单词,程序判断数组是否包含有这个单词,包含这个单词就打印出“Yes”&…...
VMWARE ESXI VMFS阵列故障 服务器数据恢复
1:河南用户一台DELL R740 3块2.4T硬盘组的RAID5,早期坏了一个盘没有及时更换,这次又坏了一个,导致整组RAID5处于数据丢失的状态, 2:该服务器装的是VMware ESXI 6.7,用户把3块硬盘寄过来进行数据…...
Cursor实现用excel数据填充word模版的方法
cursor主页:https://www.cursor.com/ 任务目标:把excel格式的数据里的单元格,按照某一个固定模版填充到word中 文章目录 注意事项逐步生成程序1. 确定格式2. 调试程序 注意事项 直接给一个excel文件和最终呈现的word文件的示例,…...
Swift 协议扩展精进之路:解决 CoreData 托管实体子类的类型不匹配问题(下)
概述 在 Swift 开发语言中,各位秃头小码农们可以充分利用语法本身所带来的便利去劈荆斩棘。我们还可以恣意利用泛型、协议关联类型和协议扩展来进一步简化和优化我们复杂的代码需求。 不过,在涉及到多个子类派生于基类进行多态模拟的场景下,…...
STM32标准库-DMA直接存储器存取
文章目录 一、DMA1.1简介1.2存储器映像1.3DMA框图1.4DMA基本结构1.5DMA请求1.6数据宽度与对齐1.7数据转运DMA1.8ADC扫描模式DMA 二、数据转运DMA2.1接线图2.2代码2.3相关API 一、DMA 1.1简介 DMA(Direct Memory Access)直接存储器存取 DMA可以提供外设…...
GitHub 趋势日报 (2025年06月08日)
📊 由 TrendForge 系统生成 | 🌐 https://trendforge.devlive.org/ 🌐 本日报中的项目描述已自动翻译为中文 📈 今日获星趋势图 今日获星趋势图 884 cognee 566 dify 414 HumanSystemOptimization 414 omni-tools 321 note-gen …...
项目部署到Linux上时遇到的错误(Redis,MySQL,无法正确连接,地址占用问题)
Redis无法正确连接 在运行jar包时出现了这样的错误 查询得知问题核心在于Redis连接失败,具体原因是客户端发送了密码认证请求,但Redis服务器未设置密码 1.为Redis设置密码(匹配客户端配置) 步骤: 1).修…...
代码随想录刷题day30
1、零钱兑换II 给你一个整数数组 coins 表示不同面额的硬币,另给一个整数 amount 表示总金额。 请你计算并返回可以凑成总金额的硬币组合数。如果任何硬币组合都无法凑出总金额,返回 0 。 假设每一种面额的硬币有无限个。 题目数据保证结果符合 32 位带…...
A2A JS SDK 完整教程:快速入门指南
目录 什么是 A2A JS SDK?A2A JS 安装与设置A2A JS 核心概念创建你的第一个 A2A JS 代理A2A JS 服务端开发A2A JS 客户端使用A2A JS 高级特性A2A JS 最佳实践A2A JS 故障排除 什么是 A2A JS SDK? A2A JS SDK 是一个专为 JavaScript/TypeScript 开发者设计的强大库ÿ…...
Go语言多线程问题
打印零与奇偶数(leetcode 1116) 方法1:使用互斥锁和条件变量 package mainimport ("fmt""sync" )type ZeroEvenOdd struct {n intzeroMutex sync.MutexevenMutex sync.MutexoddMutex sync.Mutexcurrent int…...
Git 3天2K星标:Datawhale 的 Happy-LLM 项目介绍(附教程)
引言 在人工智能飞速发展的今天,大语言模型(Large Language Models, LLMs)已成为技术领域的焦点。从智能写作到代码生成,LLM 的应用场景不断扩展,深刻改变了我们的工作和生活方式。然而,理解这些模型的内部…...
NPOI操作EXCEL文件 ——CAD C# 二次开发
缺点:dll.版本容易加载错误。CAD加载插件时,没有加载所有类库。插件运行过程中用到某个类库,会从CAD的安装目录找,找不到就报错了。 【方案2】让CAD在加载过程中把类库加载到内存 【方案3】是发现缺少了哪个库,就用插件程序加载进…...
