计算机Java项目|基于Springboot实现患者管理系统

 作者主页:编程指南针

作者简介:Java领域优质创作者、CSDN博客专家 、掘金特邀作者、多年架构师设计经验、腾讯课堂常驻讲师

主要内容:Java项目、毕业设计、简历模板、学习资料、面试题库、技术互助

文末获取源码 

项目编号:KS-032

一,项目简介

医院病患管理,Springboot+Thymeleaf+BootStrap+Mybatis,页面好看,功能完全.有登录权限拦截、忘记密码、发送邮件等功能。主要包含病患管理、信息统计、用户注册、用户登陆、病患联系等功能

二,环境介绍

语言环境:Java:  jdk1.8

数据库:Mysql: mysql5.7

应用服务器:Tomcat:  tomcat8.5.31

开发工具:IDEA或eclipse

三,系统展示

登陆

计算机Java项目|基于Springboot实现患者管理系统_第1张图片

注册

计算机Java项目|基于Springboot实现患者管理系统_第2张图片

首页

计算机Java项目|基于Springboot实现患者管理系统_第3张图片

病患管理

个人信息管理

计算机Java项目|基于Springboot实现患者管理系统_第4张图片

发邮件

四,核心代码展示

package com.liefox.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author znz
 * @Date 2021/4/19 下午 12:41
 **/
public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //登录成功之后,应该有用户的session
        Object loginUser = request.getSession().getAttribute("loginUser");


        if (loginUser == null) {
            System.err.println("loginUserSession=>"+loginUser);
            request.setAttribute("msg", "没有权限,请登录");
            /*转发到登录页*/
            request.getRequestDispatcher("/tosign-in").forward(request, response);
            return false;
        } else {
            return true;
        }
    }
}
package com.liefox.config;

import org.springframework.web.servlet.LocaleResolver;
import org.thymeleaf.util.StringUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @Author znz
 * @Date 2021/4/19 上午 9:44
 * 国际化
 **/
public class MyLocaleResolver implements LocaleResolver {
    //解析请求
    @Override
    public Locale resolveLocale(HttpServletRequest httpServletRequest) {
        //获取请求中的语言参数
        String language = httpServletRequest.getParameter("l");
        Locale locale = Locale.getDefault();//如果没有就使用默认值
        //如果请求的链接携带了国际化的参数
        if (!StringUtils.isEmpty(language)) {
            //zh_CN
            String[] split = language.split("_");
            //国家地区
            locale = new Locale(split[0], split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Locale locale) {

    }
}

package com.liefox.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author znz
 * @Date 2021/4/18 下午 2:40
 **/
@Configuration
public class MyMvcConfig implements WebMvcConfigurer {
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        /**
         * 医生页
         * */
        /*欢迎页*/
        registry.addViewController("/").setViewName("doctor/sign-in");
        /*首页*/
        registry.addViewController("/index").setViewName("doctor/index");
        /*去登录*/
        registry.addViewController("/tosign-in").setViewName("doctor/sign-in");
        /*去注册*/
        registry.addViewController("/tosign-up").setViewName("doctor/sign-up");
        /*去忘记密码*/
        registry.addViewController("/torecoverpw").setViewName("doctor/pages-recoverpw");
        /*去修改个人信息*/
        registry.addViewController("/topro-edit").setViewName("doctor/main/profile-edit");
        /*去邮箱*/
        registry.addViewController("/toemail").setViewName("doctor/app/email-compose");
        /*去编辑病患表格*/
        registry.addViewController("/totable").setViewName("doctor/app/table-editable");
        /*去修改病患信息*/
        registry.addViewController("/toRePatientInfo").setViewName("doctor/app/rePatientInfo");
        /*去增加病患信息*/
        registry.addViewController("/toAddPatientInfo").setViewName("doctor/app/addPatientInfo");
        /*去群聊天*/
        registry.addViewController("/toChat").setViewName("doctor/main/chat");


        /**
         * 医生页
         * */
    }

    //自定义的国际化就生效了
    @Bean
    public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }


    //配置登录拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                /*拦截*/
                .addPathPatterns("/**")
                /*放行*/
                .excludePathPatterns(
                        "/tosign-in"
                        , "/tosign-up"
                        , "/sign-in"
                        , "/sign-up"
                        , "/torecoverpw"
                        , "/recPwEmail"
                        , "/recPw"
                        , "/"
                        , "/css/**"
                        , "/js/**"
                        , "/images/**"
                        , "/app/**"
                        , "/fonts/**"
                        , "/fullcalendar/**"
                );
    }


}
package com.liefox.controller;

import com.liefox.pojo.Patient;
import com.liefox.pojo.User;
import com.liefox.service.PatientService;
import com.sun.org.apache.xpath.internal.operations.Mod;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.UUID;

/**
 * @Author znz
 * @Date 2021/4/21 下午 1:35
 **/
@Controller
public class PatientController {

    @Autowired
    private PatientService patientService;
    @Autowired
    JavaMailSenderImpl mailSender;

    /*获取全部病者信息*/
    @RequestMapping("/getPatientInfo")
    public String getPatientInfo(Model model) {
        List patientInfo = patientService.getPatientInfo();

        model.addAttribute("patientInfos", patientInfo);
        return "doctor/app/table-editable";
    }

    /*删除病人信息根据UUID*/
    @RequestMapping("/delPatientInfoByUUID/{UUID}")
    public String delPatientInfoByUUID(@PathVariable("UUID") String UUID) {
        patientService.delPatientInfoByUUID(UUID);
        return "redirect:/getPatientInfo";
    }

    /*获取病人信息根据UUID*/
    @RequestMapping("/getPatientInfoByUUID/{UUID}")
    public String getPatientInfoByUUID(@PathVariable("UUID") String UUID, Model model) {
        Patient patientInfoByUUID = patientService.getPatientInfoByUUID(UUID);
        System.out.println(patientInfoByUUID);
        model.addAttribute("patientInfoByUUID", patientInfoByUUID);
        return "doctor/app/rePatientInfo";
    }

    /*更新病人信息根据UUID*/
    @RequestMapping("/upPatientInfoByUUID")
    public String upPatientInfoByEmail(Patient patient) {
        patientService.upPatientInfoByUUID(patient);
        return "redirect:/getPatientInfo";
    }

    /*去新增病患页*/
    @RequestMapping("/toAddPatientInfo")
    public String toAddPatientInfo(Model model) {
        String uuid = UUID.randomUUID().toString();
        model.addAttribute("uuid", uuid);
        return "doctor/app/addPatientInfo";
    }


    /*新增病患*/
    @RequestMapping("/addPatientInfo")
    public String addPatientInfo(Patient patient, Model model) {
        int i = patientService.addPatientInfo(patient);
        model.addAttribute("msg", "添加成功!");
        return "redirect:/getPatientInfo";
    }

    /*去发邮件页面*/
    @RequestMapping("/toEmail/{Email}")
    public String toEmail(@PathVariable("Email") String Email, Model model) {
        model.addAttribute("PatientEmail", Email);
        return "doctor/app/email-compose";
    }

    /*发邮件给病者*/
    @RequestMapping("/sentEmail")
    public String recPwEmail(String ToEmail, String CcEmail, String subject, String Message,
                             HttpSession session, Model model) {
        try {
            //邮件设置
            SimpleMailMessage message = new SimpleMailMessage();
            //主题
            message.setSubject(subject);
            //内容
            message.setText(Message);
            //收件人
            message.setTo(ToEmail);
            //发件人
            message.setFrom(CcEmail);
            //发送
            mailSender.send(message);
            model.addAttribute("info", "邮件发送成功!");
            return "doctor/app/email-compose";
        } catch (Exception e) {
            model.addAttribute("info", "邮箱地址不正确!");
            return "doctor/app/email-compose";
        }


    }

}
package com.liefox.controller;

import com.liefox.pojo.Patient;
import com.liefox.pojo.User;
import com.liefox.service.PatientService;
import com.liefox.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSenderImpl;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author znz
 * @Date 2021/4/18 下午 5:30
 **/
@Controller
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    JavaMailSenderImpl mailSender;
    @Autowired
    private PatientService patientService;

    /**
     * 生成6位随机数验证码
     */
    public static int randomCode() {
        return (int) ((Math.random() * 9 + 1) * 100000);
    }

    /**
     * i:验证码
     */
    static int i = randomCode();

    /*注册*/
    @PostMapping("/sign-up")
    public String signup(User user, Model model) {
        try {
            int i = userService.Signup(user);
            if (i != 0) {
                System.out.println(user + "=》注册成功");
                model.addAttribute("msg", "注册成功!");
                return "/doctor/sign-in";
            }
        } catch (Exception e) {
            System.err.println(user + "=>注册失败");
            model.addAttribute("msg", "该邮箱已注册!");
            return "/doctor/sign-up";
        }
        return null;
    }

    /*登录*/
    @RequestMapping("/sign-in")
    public String signin(User user, Model model, HttpSession session, String Email) {
        User signin = userService.Signin(user);
        User userInfo = userService.getUserInfo(Email);
        System.out.println(userInfo + "用户信息");
        String userName = userService.getUserName(user.getEmail(), user.getPassword());
        if (signin != null) {
            /*用户信息*/
            session.setAttribute("UserInfo", userInfo);
            /*登录拦截*/
            session.setAttribute("loginUser", userName);
            /*获取病人病情信息*/
            List patientInfo = patientService.getPatientInfo();
            long count = patientInfo.stream().count();
            model.addAttribute("patientInfos",patientInfo);
            model.addAttribute("count",count);
            /*获取医生信息*/
            List userinfo = userService.getUser();
            model.addAttribute("userInfos",userinfo);
            /**/
            session.setAttribute("Email", Email);
            System.out.println(user + "=》登录成功");
            return "/doctor/index";
        } else {
            System.err.println(user + "=》登录失败");
            model.addAttribute("msg", "邮箱地址或密码错误!");
            return "/doctor/sign-in";
        }

    }
    /*去首页*/
    @RequestMapping("/toindex")
    public String toindex(Model model){
        /*获取病人病情信息*/
        List patientInfo = patientService.getPatientInfo();
        model.addAttribute("patientInfos", patientInfo);
        long count = patientInfo.stream().count();
        model.addAttribute("count",count);
        /*获取医生信息*/
        List user = userService.getUser();
        model.addAttribute("userInfos",user);
        return "/doctor/index";
    }

    /*注销*/
    @RequestMapping("/logout")
    public String logout(HttpSession session) {
        session.removeAttribute("loginUser");
        return "redirect:/sign-in.html";
    }

    /*忘记密码发邮件*/
    @RequestMapping("/recPwEmail")
    public String recPwEmail(String Email, HttpSession session, Model model) {
        System.out.println(Email + "发送了验证码");
        System.err.println(i);

        session.setAttribute("Email", Email);
        try {
            //邮件设置
            SimpleMailMessage message = new SimpleMailMessage();
            //主题
            message.setSubject("Shiqi-验证码");
            //内容-验证码
            message.setText(String.valueOf(i));
            //收件人
            message.setTo(Email);
            //发件人
            message.setFrom("[email protected]");
            //发送
            mailSender.send(message);
            model.addAttribute("info", "验证码发送成功!");
            return "/doctor/pages-recoverpw";
        } catch (Exception e) {
            System.err.println("cs");
            model.addAttribute("info", "邮箱地址不正确!");
            return "/doctor/pages-recoverpw";
        }


    }

    /*判断验证码正确,并重置密码*/
    @RequestMapping("/recPw")
    public String recPw(String Email, int token, String Password, Model model) {
        System.out.println(Email + "    重置密码为=》" + Password + "     输入的验证码为     " + i);

        if (token == i) {
            userService.recPw(Email, Password);
            model.addAttribute("info", "修改成功!");
            return "/doctor/sign-in";
        } else {
            model.addAttribute("error", "验证码错误!");
            return "/doctor/pages-recoverpw";
        }

    }

    /*查看个人信息页面*/
    @RequestMapping("/getUserInfo")
    public String getUserInfo() {
        return "/doctor/main/profile-edit";
    }

    /*修改个人信息*/
    @RequestMapping("/updateUserInfo")
    public String updateUserInfo(User user, Model model) {
        int i = userService.updateUserInfo(user);
        if (i != 0) {
            model.addAttribute("msg","下次登录生效!");
            return "/doctor/main/profile-edit";
        }else {
            System.err.println("111111111");
            model.addAttribute("msg","不修改就别乱点!");
            return "/doctor/main/profile-edit";
        }

    }

    /*修改密码*/
    @RequestMapping("/upPw")
    public String upPw(String Email,String Password,Model model){
            userService.upPw(Email, Password);
            model.addAttribute("info","修改成功!");
            return "doctor/sign-in";


    }


}

五,项目总结

整个系统功能模块不是很多,但是系统选题立意新颖,功能简洁明了,个性功能鲜明突出,像邮件发送、图片报表展示和统计等,可以做毕业设计或课程设计使用。

你可能感兴趣的:(java实战项目,java,spring,boot,开发语言)