网站收费系统平台,vi设计应用部分有哪些,wordpress编辑器提示失败,制作网站的基本工作流程基于 JAVASSM#xff08;Java Spring Spring MVC MyBatis#xff09;框架开发一个医院挂号系统是一个实用的项目。
步骤一#xff1a;需求分析
明确系统需要实现的功能#xff0c;比如#xff1a;
用户注册和登录查看医生列表预约挂号查看预约记录取消预约管理员管…基于 JAVASSMJava 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.urljdbc:mysql://localhost:3306/hospital_registration?useSSLfalseserverTimezoneUTC
spring.datasource.usernameroot
spring.datasource.passwordroot
spring.datasource.driver-class-namecom.mysql.cj.jdbc.Drivermybatis.mapper-locationsclasspath:mapper/*.xmlspring-mvc.xml
beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:mvchttp://www.springframework.org/schema/mvcxsi:schemaLocationhttp://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.xsdcontext:component-scan base-packagecom.hospital/mvc:annotation-driven/bean classorg.springframework.web.servlet.view.InternalResourceViewResolverproperty nameprefix value/WEB-INF/views//property namesuffix value.jsp//bean/beansmybatis-config.xml
configurationmappersmapper resourcemapper/UserMapper.xml/mapper resourcemapper/DoctorMapper.xml/mapper resourcemapper/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)ListDoctor 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})ListAppointment 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 ListDoctor 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 ListAppointment 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) {ListDoctor 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) {ListAppointment appointments appointmentService.getAppointmentsByUserId(userId);model.addAttribute(appointments, appointments);return appointments;}GetMapping(/makeAppointment)public String showMakeAppointmentForm(RequestParam(userId) int userId, Model model) {ListDoctor 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 contentTypetext/html;charsetUTF-8 languagejava %
html
headtitleLogin/title
/head
body
h2Login/h2
form action${pageContext.request.contextPath}/login methodpostUsername: input typetext nameusernamebrPassword: input typepassword namepasswordbrinput typesubmit valueLogin
/form
c:if test${not empty error}p stylecolor: red${error}/p
/c:if
/body
/htmldoctors.jsp
% page contentTypetext/html;charsetUTF-8 languagejava %
% taglib urihttp://java.sun.com/jsp/jstl/core prefixc %
html
headtitleDoctors/title
/head
body
h2Doctors/h2
tabletrthName/ththDepartment/ththIntroduction/ththSchedule/ththAction/th/trc:forEach items${doctors} vardoctortrtd${doctor.name}/tdtd${doctor.department}/tdtd${doctor.introduction}/tdtd${doctor.schedule}/tdtda href${pageContext.request.contextPath}/doctor/${doctor.id}View/aa href${pageContext.request.contextPath}/editDoctor/${doctor.id}Edit/aa href${pageContext.request.contextPath}/deleteDoctor/${doctor.id}Delete/a/td/tr/c:forEach
/table
a href${pageContext.request.contextPath}/addDoctorAdd New Doctor/a
/body
/htmlmakeAppointment.jsp
% page contentTypetext/html;charsetUTF-8 languagejava %
% taglib urihttp://java.sun.com/jsp/jstl/core prefixc %
html
headtitleMake Appointment/title
/head
body
h2Make Appointment/h2
form action${pageContext.request.contextPath}/makeAppointment methodpostinput typehidden nameuserId value${userId}Doctor:select namedoctorIdc:forEach items${doctors} vardoctoroption value${doctor.id}${doctor.name} (${doctor.department})/option/c:forEach/selectbrAppointment Time: input typedatetime-local nameappointmentTimebrinput typesubmit valueMake Appointment
/form
/body
/html步骤十一测试与调试
对每个功能进行详细测试确保所有功能都能正常工作。
步骤十二部署与发布
编译最终版本的应用程序并准备好 WAR 文件供 Tomcat 或其他应用服务器部署。