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 */;
项目链接地址:直达项目,点吧