栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

SpringMVC 增删改查小案例-医院挂号系统

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

SpringMVC 增删改查小案例-医院挂号系统


SpringMVC
  • 配置文件
    • pom.xml
    • application
    • spring-mvc
    • WEB.xml
  • 创建实体类
  • 创建mapper接口
  • 创建Service接口
  • 设置mapper
  • 实现service
  • 配置控制层
  • 前端界面
  • 新增界面
  • 目录结构
  • 配置tomcat

配置文件 pom.xml


    4.0.0

    org.example
    医疗系统
    1.0-SNAPSHOT
    
        
            junit
            junit
            4.11
            test
        
        
            mysql
            mysql-connector-java
            5.1.47
        
        
            org.mybatis
            mybatis
            3.5.9
        
        
            javax.servlet
            javax.servlet-api
            3.1.0
        
        
            javax.servlet.jsp
            javax.servlet.jsp-api
            2.3.3
        
        
            org.springframework
            spring-core
            4.3.18.RELEASE
            
        
        
            org.springframework
            spring-web
            4.3.18.RELEASE
        
        
            org.springframework
            spring-context
            4.3.18.RELEASE
        
        
            org.springframework
            spring-beans
            4.3.18.RELEASE
        
        
            org.springframework
            spring-webmvc
            4.3.18.RELEASE
        

        
            org.springframework
            spring-jdbc
            4.3.18.RELEASE
        
        
            org.springframework
            spring-tx
            4.3.18.RELEASE
        
        
            org.mybatis
            mybatis-spring
            2.0.6
        
        
            javax.servlet
            jstl
            1.2
        

        
            commons-dbcp
            commons-dbcp
            1.4
        
        
            commons-fileupload
            commons-fileupload
            1.3.1
        
        
            commons-io
            commons-io
            2.4
        


        
            com.alibaba
            fastjson
            2.0.4
        
        
            com.alibaba
            druid
            1.1.10
        

        
            com.alibaba
            druid-spring-boot-starter
            1.2.9
        
    
    
        8
        8
    


application


    
        
    

    
        
        
        
        
    

    
        
        
        
    

    
        
        
    

    
        
    

spring-mvc


    

    

    

    
        
        
        
    

WEB.xml


    index.jsp


    contextConfigLocation
    classpath:applicationContext.xml

    
        org.springframework.web.context.ContextLoaderListener
    

    CharacterEncodingFilter
    org.springframework.web.filter.CharacterEncodingFilter
    
        encoding
        utf-8
    
    
        forceEncoding
        true
    

    
        CharacterEncodingFilter
        /*
    
    
        springmvc
        org.springframework.web.servlet.DispatcherServlet
        
            contextConfigLocation
            classpath:spring-mvc.xml
        
        1
        true
    
    
        springmvc
        /
    

创建实体类
package com.item.model;

public class Users {
    private int id;
    private String name;
    private String sex;
    private int age;
    private String phone;
    private String department;
    private String type;
    private Double price;
    private String state;
    private String register_time;

    public Users(int id, String name, String sex, int age, String phone, String department, String type, Double price, String state, String register_time) {
        this.id = id;
        this.name = name;
        this.sex = sex;
        this.age = age;
        this.phone = phone;
        this.department = department;
        this.type = type;
        this.price = price;
        this.state = state;
        this.register_time = register_time;
    }

    public int getId() {
        return id;
    }

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

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getDepartment() {
        return department;
    }

    public void setDepartment(String department) {
        this.department = department;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Double getPrice() {
        return price;
    }

    public void setPrice(Double price) {
        this.price = price;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getRegister_time() {
        return register_time;
    }

    public void setRegister_time(String register_time) {
        this.register_time = register_time;
    }

    public Users() {
    }
}


创建mapper接口
package com.item.dao;

import com.item.model.Users;
import org.apache.ibatis.annotations.Param;

import java.util.List;

public interface UserMapperInterface {
//    查询全部
    ListSelectAll();
//    模糊查询
    ListSelectVague(@Param("name") String name,
                           @Param("Type") String type,
                           @Param("Depa") String Depa);
    //    新增
    int Inserts  (@Param("username") String name,
                 @Param("Sex") String Sex,
                 @Param("ages") String ages,
                 @Param("phone") String phone,
                 @Param("deap") String deap, @Param("Types") String Types, @Param("Proice") String Proice);
}


创建Service接口
package com.item.service;

import com.item.model.Users;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import java.util.List;

public interface UserServiceInterface {
    //    查询全部
    List SelectAll();
    //    模糊查询
    ListSelectVague(@Param("name") String name,
                           @Param("Type") String type,
                           @Param("Depa") String Depa);
//    新增
    int Inserts  (@Param("username") String name,
                 @Param("Sex") String Sex,
                 @Param("ages") String ages,
                 @Param("phone") String phone,
                 @Param("deap") String deap, @Param("Types") String Types, @Param("Proice") String Proice);

}


设置mapper





        select * from tb_patient where name like "%${name}%" and type LIKE "%${Type}%" and department Like "%${Depa}%"
    

    
        INSERT INTO `hospital_db`.`tb_patient` (`id`, `name`, `sex`, `age`, `phone`, `department`, `type`, `price`, `state`, `register_time`) VALUES
        (null , '${username}', '${Sex}', '${ages}', '${phone}', '${deap}', '${Types}', '${Proice}', '未就诊', NOW());
    

实现service
package com.item.serviceimpl;

import com.alibaba.druid.filter.AutoLoad;
import com.item.dao.UserMapperInterface;
import com.item.model.Users;
import com.item.service.UserServiceInterface;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class UserServiceImpl implements UserServiceInterface {
    @Autowired
    private UserMapperInterface userMapperInterface;
    @Override
    public List SelectAll() {
        return userMapperInterface.SelectAll();
    }

    @Override
    public List SelectVague(String name, String type, String Depa) {
        return userMapperInterface.SelectVague(name,type,Depa);
    }

    @Override
    public int Inserts(String name, String Sex, String ages, String phone, String deap, String Types, String Proice) {
        return userMapperInterface.Inserts(name,Sex,ages,phone,deap,Types,Proice);

    }




}

配置控制层
```css
package com.item.controller;

import com.item.dao.UserMapperInterface;
import com.item.model.Users;
import com.item.service.UserServiceInterface;
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 javax.servlet.http.HttpServletRequest;
import java.util.List;
@Controller
public class UsersController  {
    @Autowired
    private UserServiceInterface userServiceInterface;
    @GetMapping("/GetInto")
    public String GetInto(HttpServletRequest  request, Model model) {
        List o = userServiceInterface.SelectAll();
        model.addAttribute("list", o);
        return "GetInto";
    }
//    模糊查询
    @GetMapping("/GetVague")
    public String GetVague(HttpServletRequest request,Model model){
        String name = request.getParameter("username");
        String Types = request.getParameter("Types");
        if (Types.equals("空")){
            Types="";
        }
        String Deap = request.getParameter("Deap");
        List users = userServiceInterface.SelectVague(name, Types, Deap);
        model.addAttribute("list", users);
        return "/GetInto";
    }
    @GetMapping("/Insert")
    public String Insert(){
        return "Insert";
    }
//    新增
    @GetMapping("/AddInsert")
    public String Insert(HttpServletRequest request,Model model){
        String username = request.getParameter("username");
        String Sex = request.getParameter("Sex");
        String ages = request.getParameter("ages");
        String phone = request.getParameter("phone");
        String deap = request.getParameter("deap");
        String Types = request.getParameter("Types");
        String Proice="";
        if(Types.equals("普通医生")){
            Proice="8.00";
        }else if(Types.equals("副主任医生")){
            Proice="17.00";
        }else if(Types.equals("专家医生")){
            Proice="25.00";
        }
        userServiceInterface.Inserts(username,Sex,ages,phone,deap,Types,Proice);
        return "redirect:/GetInto";
    }
}

前端界面
<%@ page import="com.item.model.Users" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: 30856
  Date: 2022/06/11
  Time: 1:59
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    挂号系统


<% List list = (List) request.getAttribute("list");%>
医院就诊挂号系统
患者姓名: 医生类别: 科室:
<% for(Users users:list){%> <%}%>
编号 姓名 性别 年龄 电话 科室 医生类别 价格 挂号时间 操作
<%=users.getId()%> <%=users.getName()%> <%=users.getSex()%> <%=users.getPhone()%> <%=users.getDepartment()%> <%=users.getType()%> <%=users.getPrice()%> <%=users.getRegister_time()%> <%=users.getState()%> 删除
新增界面
<%--
  Created by IntelliJ IDEA.
  User: 30856
  Date: 2022/06/11
  Time: 13:48
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    患者挂号



患者挂号


    
姓 名 性 别 男 女 年 龄 电 话 科 室 医师类别 (价格:0元)
目录结构

配置tomcat

省略。。

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/966742.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号