SSM学生健康后台管理系统(小型demo)三完成Controller层及前端展示,完成所有功能

SSM学生健康后台管理系统(小型demo)三完成Controller层及前端展示,完成所有功能

1.controller层
因是练习项目所以没有将controller分开

StudentInfoController

package com.studentheathly.controller;

import com.studentheathly.entity.StudentInfo;
import com.studentheathly.entity.StudentState;
import com.studentheathly.service.StudentInfoService;
import com.studentheathly.service.StudentStateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/studentinfo")
public class StudentInfoController {
    @Autowired
    private StudentInfoService studentInfoService;
    @Autowired
    private StudentStateService studentStateService;

    //展示学生信息
    @RequestMapping("/showinfo")
    public String showInfo(Model model){
        List<StudentInfo> studentInfos = studentInfoService.getStudentInfo();
        model.addAttribute("studentInfos",studentInfos);
        return "showInfo";
    }

    //删除学生信息
    @RequestMapping("/delete/{sId}")
    public String deleteInfo(@PathVariable("sId") int sid){
        studentInfoService.deleteStudentInfoById(sid);
        return "redirect:/studentinfo/showinfo";
    }

    //跳转新增页面
    @RequestMapping("/newinfo")
    public String newInfoPage(){
        return "newInfo";
    }

    //添加学生
    @RequestMapping("/addinfo")
    public String addInfo(StudentInfo studentInfo){
        studentInfoService.addStudentInfo(studentInfo);
        return "redirect:/studentinfo/showinfo";
    }

    //根据id查询展示健康信息
    @RequestMapping("/selectstate/{sId}")
    public String selectState(@PathVariable("sId")int sid,Model model){
        List<StudentState> studentStates = studentStateService.getStudentStateBySid(sid);
        model.addAttribute("studentStates",studentStates);
        return "showState";
    }

    //跳转新增健康信息页面
    @RequestMapping("/newstate")
    public String newState(Model model){

        return "newState";
    }

    //新增健康信息
    @RequestMapping("/addstate")
    public String addState(StudentState studentState){
        studentStateService.addStudentState(studentState);
        return "redirect:/studentinfo/showinfo";
    }

}

2.前端页面

index.jsp

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/16 0016
  Time: 19:34
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title>首页</title>
  </head>
  <body>
  <a href="/studentinfo/showinfo">展示学生信息</a>
  </body>
</html>

showInfo.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/21 0021
  Time: 8:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>展示学生信息</title>
</head>
<body>
<a href="/studentinfo/newinfo">新增</a>
    <div>
        <table border="1">
            <thead>
            <tr>
                <th>姓名</th>
                <th>性别</th>
                <th>年龄</th>
                <th>身份证</th>
                <th>手机</th>
                <th colspan="2">操作</th>
            </tr>
            </thead>
            <tbody>
            <c:forEach var="studentInfo" items="${studentInfos}">
                <tr>
                    <td>${studentInfo.sName}</td>
                    <td>${studentInfo.sSex}</td>
                    <td>${studentInfo.sAge}</td>
                    <td>${studentInfo.sIdcard}</td>
                    <td>${studentInfo.sPhoneno}</td>
                    <td><a href="/studentinfo/selectstate/${studentInfo.sId}">健康信息</a></td>
                    <td><a href="/studentinfo/delete/${studentInfo.sId}">删除</a></td>
                </tr>
            </c:forEach>
            </tbody>
        </table>
    </div>
</body>
</html>

showState.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/21 0021
  Time: 9:36
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>展示健康信息</title>
</head>
<body>
<a href="/studentinfo/newstate">新增</a>
<div>
    <table border="1">
        <thead>
        <tr>
            <th>记录时间</th>
            <th>编号</th>
            <th>健康状态</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach var="studentState" items="${studentStates}">
            <tr>
                <td>${studentState.addTime}</td>
                <td>${studentState.sId}</td>
                <td>${studentState.bodyInfo}</td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
</div>
<hr/>

<form action="/studentinfo/addstate" method="post">
    健康状态:<input type="text" name="bodyInfo" /><br></br>
    关联编号:<input type="text" name="sId" value="${sId}"><br></br>
    记录时间:<input type="date" name="addTime" /><br></br>
    <input type="submit"  value="提交"/>
</form>
</body>
</html>

newInfo.jsp

<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/21 0021
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增</title>
</head>
<body>
<form action="/studentinfo/addinfo" method="post">
    姓名:<input type="text" name="sName" /><br></br>
    年龄:<input type="text" name="sAge" /><br></br>
    身份证:<input type="text" name="sIdcard" /><br></br>
    电话:<input type="text" name="sPhoneno" /><br></br>
    性别:男<input type="radio" name="sSex" value="" /><input type="radio" name="sSex" value="" /><br></br>
    <input type="submit"  value="提交"/>
</form>
</body>
</html>

newState.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/21 0021
  Time: 9:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>新增</title>
</head>
<body>
<form action="/studentinfo/addstate" method="post">
    健康状态:<input type="text" name="bodyInfo" /><br></br>
    关联编号:<input type="text" name="sId" value="<%=request.getParameter("id")%>"><br></br>
    记录时间:<input type="datetime" name="addTime" /><br></br>
    <input type="submit" value="提交"/>
</form>
</body>
</html>

此练习到这里就结束了哦!前端页面可以自己美化哦!
附SQL

/*
SQLyog Ultimate v11.24 (32 bit)
MySQL - 5.5.57 : Database - students
*********************************************************************
*/


/*!40101 SET NAMES utf8 */;

/*!40101 SET SQL_MODE=''*/;

/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE /*!32312 IF NOT EXISTS*/`students` /*!40100 DEFAULT CHARACTER SET utf8 */;

USE `students`;

/*Table structure for table `studentinfo` */

DROP TABLE IF EXISTS `studentinfo`;

CREATE TABLE `studentinfo` (
  `sid` int(11) NOT NULL AUTO_INCREMENT COMMENT '学生id',
  `sname` varchar(32) NOT NULL COMMENT '学生姓名',
  `sage` int(11) NOT NULL COMMENT '学生年龄',
  `sidcard` varchar(32) NOT NULL COMMENT '学生身份证号',
  `sphoneNo` varchar(11) NOT NULL COMMENT '学生手机号',
  `ssex` varchar(2) NOT NULL COMMENT '性别',
  PRIMARY KEY (`sid`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

/*Data for the table `studentinfo` */

insert  into `studentinfo`(`sid`,`sname`,`sage`,`sidcard`,`sphoneNo`,`ssex`) values (1,'admin',19,'410001200010101234','15632106666','男'),(2,'HOUPU',100,'410001200010102999','13399996666','男'),(3,'SG',100,'410001200010102999','13399999999','男'),(7,'ss',19,'4131322200001012365','152835396','on'),(8,'唐三',20,'432221200001012365','15243538695','on');

/*Table structure for table `studentstate` */

DROP TABLE IF EXISTS `studentstate`;

CREATE TABLE `studentstate` (
  `bid` int(11) NOT NULL AUTO_INCREMENT,
  `bodyinfo` varchar(32) NOT NULL,
  `sid` int(11) NOT NULL,
  `addtime` datetime NOT NULL,
  PRIMARY KEY (`bid`),
  KEY `sid` (`sid`),
  CONSTRAINT `studentstate_ibfk_1` FOREIGN KEY (`sid`) REFERENCES `studentinfo` (`sid`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

/*Data for the table `studentstate` */

insert  into `studentstate`(`bid`,`bodyinfo`,`sid`,`addtime`) values (1,'健康、接触病患',1,'2021-06-11 14:45:30'),(2,'健康',2,'2021-06-11 14:45:43'),(3,'接触病患',3,'2021-06-11 14:46:01');

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

项目链接地址:直达项目,点吧

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沐凌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值