在本月我们学习了Vue的基础知识,结合所学的内容,做了一个小的项目健康管理系统,开发所含的需求,检查项或检查组的增删改查,导入导出,缓存数据用定时任务删除,以及柱状图和柱状图,若本文对你有所帮助,建议一键三连。
创建maven项目模块,导入相关的jar包以及依赖。
,
建表建库:
create table kew(
id int primary key auto_increment,
kid varchar(20),
name varchar(20),
shi varchar(20),
xing varchar(20),
xue varchar(20),
ming varchar(20)
)
create table studentw(
id int primary key auto_increment,
sid varchar(20),
name varchar(20),
sex varchar(20),
age int,
address varchar(20),
zhu varchar(20)
)
create table zhongjian(
s_id int,
k_id int,
foreign key (s_id) references studentw (id),
foreign key (k_id) references kew (id)
)
insert into studentw (id, sid, name, sex, age, address, zhu)
values
(1,'100','小明','男',21,'河南','优秀'),
(2,'101','小红','男',21,'南阳','低级'),
(3,'102','小黑','男',41,'内乡','H欧'),
(4,'103','小有','女',11,'河南','优秀');
insert into kew (id, kid, name, shi, xing, xue, ming)
values
(1,'200','大数据','10','理科','500','理科据就是好'),
(2,'201','语文','10','文科','500','大就是好'),
(3,'202','英语','11','文科','100','大就是好'),
(4,'203','数学','22','理科','900','大就是好'),
(5,'204','政治','13','文科','100','大就是好');
insert into zhongjian (s_id, k_id)
values
(1,1),
(2,2),
(3,3),
(4,1),
(1,1);
创建对应的实体类:
public class Student implements Serializable {
private Integer id;
private String sid;
private String name;
private String sex;
private Integer age;
private String address;
private String zhu;
private String names;
private List k;
提供get和set方法
}
public class Ke implements Serializable {
private Integer id;
private String kid;
private String name;
private String shi;
private String xing;
private String xue;
private String ming;
}
检查项前端:
传智健康
预约管理
检查项管理
首页
预约管理
检查项管理
查询
新建
编辑
删除
controller:
package com.jiyun.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSON;
import com.jiyun.constant.MessageConstant;
import com.jiyun.entity.PageResult;
import com.jiyun.entity.QueryPageBean;
import com.jiyun.entity.Result;
import com.jiyun.pojo.Ke;
import com.jiyun.service.KeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.util.List;
@RestController
@RequestMapping("ke")
public class KeController {
@Autowired
JedisPool jedisPool;
@Reference
KeService keService;
@RequestMapping("findPage")
public PageResult findPage (@RequestBody QueryPageBean queryPageBean){
return keService.findPage(queryPageBean);
}
@RequestMapping("add")
public Result add (@RequestBody Ke ke){
keService.add(ke);
Jedis redis = jedisPool.getResource();
String s = JSON.toJSONString(ke);
redis.lpush("list",s);
return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS);
}
@RequestMapping("findAll")
public Result findAll (){
List list= keService.findAll();
return new Result(true, MessageConstant.ADD_CHECKITEM_SUCCESS,list);
}
@RequestMapping("update")
public Result update (@RequestBody Ke ke){
Jedis redis = jedisPool.getResource();
// 通过这个对象获取id
Integer id = ke.getId();
// 通过这个id 返回的是对象
Ke s= keService.getid(id);
String s1 = JSON.toJSONString(s);
redis.lpush("list",s1);
keService.update(ke);
return new Result(true, MessageConstant.EDIT_CHECKITEM_SUCCESS);
}
@RequestMapping("del")
public Result del (Integer id){
Integer count=keService.getids(id);
if(count>0){
return new Result(false, "数据有关联,不能删除");
}
keService.del(id);
return new Result(true, MessageConstant.DELETE_CHECKITEM_SUCCESS);
}
}
service
package com.jiyun.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jiyun.entity.PageResult;
import com.jiyun.entity.QueryPageBean;
import com.jiyun.mapper.KeMapper;
import com.jiyun.pojo.Ke;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@Service
public class KeServiceimpl implements KeService{
@Autowired
KeMapper keMapper;
@Override
public PageResult findPage(QueryPageBean queryPageBean) {
PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
List list=keMapper.findPage(queryPageBean.getQueryString());
PageInfo page = new PageInfo<>(list);
return new PageResult( page.getTotal(),page.getList());
}
@Override
public void add(Ke ke) {
keMapper.add(ke);
}
@Override
public void update(Ke ke) {
keMapper.update(ke) ;
}
@Override
public void del(Integer id) {
keMapper.del(id) ;
}
@Override
public List findAll() {
return keMapper.findAll();
}
@Override
public Ke getid(Integer id) {
return keMapper.getifd(id);
}
@Override
public Integer getids(Integer id) {
return keMapper.getwq(id);
}
}
mapper.xml
insert into kew ( kid, name, shi, xing, xue, ming)
values (#{kid},#{name},#{shi},#{xing},#{xue},#{ming})
update kew set kid=#{kid}, name=#{name}, shi=#{shi}, xing=#{xing}, xue=#{xue}, ming=#{ming} where id=#{id}
delete from kew where id=#{id}
检查项效果展示:
添加:
修改:
检查组:
前端:
传智健康
预约管理检查组管理
首页
预约管理
检查组管理
查询
新建
上传文件
下载文件
{{ scope.row.sex == '0' ? '不限' : scope.row.sex == '1' ? '男' : '女'}}
编辑
删除
选择
课程编码
课程名称
课程说明
选择
课程编码
课程名称
课程说明
controller:
package com.jiyun.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.jiyun.constant.MessageConstant;
import com.jiyun.entity.PageResult;
import com.jiyun.entity.QueryPageBean;
import com.jiyun.entity.Result;
import com.jiyun.pojo.Ke;
import com.jiyun.pojo.Student;
import com.jiyun.service.StudetnService;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletResponse;
import java.net.URLEncoder;
import java.util.List;
@RestController
@RequestMapping("student")
public class StudentController {
@Reference
StudetnService studetnService;
@RequestMapping("findPage")
public PageResult findPage (@RequestBody QueryPageBean queryPageBean){
return studetnService.findPage(queryPageBean);
}
@RequestMapping("add")
public Result add (@RequestBody Student student,Integer[] ids){
studetnService.add(student,ids);
return new Result(true, MessageConstant.ADD_CHECKGROUP_SUCCESS);
}
@RequestMapping("update")
public Result update (@RequestBody Student student,Integer[] ids){
studetnService.update(student,ids);
return new Result(true, MessageConstant.EDIT_CHECKGROUP_SUCCESS);
}
@RequestMapping("del")
public Result del (Integer id){
studetnService.del(id);
return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS);
}
@RequestMapping("getid")
public Result getid (Integer id){
List list= studetnService.getid(id);
return new Result(true, MessageConstant.DELETE_CHECKGROUP_SUCCESS,list);
}
@RequestMapping("/export1")
public void export1 (HttpServletResponse response) throws Exception {
//创建空的工作薄
HSSFWorkbook workbook = new HSSFWorkbook();
// 创建空的表
HSSFSheet sheet = workbook.createSheet();
//创建一个数组
String[] tital={"编号","名称","性别","年龄","地址","说明","课程说明"};
HSSFRow row = sheet.createRow(0);
for (int i = 0; i < tital.length; i++) {
row.createCell(i).setCellValue(tital[i]);
}
// 查询数据库
List list=studetnService.fan3();
for (int i = 0; i < list.size(); i++) {
row = sheet.createRow(i+1);
row.createCell(0).setCellValue(list.get(i).getSid());
row.createCell(1).setCellValue(list.get(i).getName());
row.createCell(2).setCellValue(list.get(i).getSex());
row.createCell(3).setCellValue(list.get(i).getAge());
row.createCell(4).setCellValue(list.get(i).getAddress());
row.createCell(5).setCellValue(list.get(i).getZhu());
row.createCell(6).setCellValue(list.get(i).getNames());
}
//7.把工作簿对象返回给前端浏览
response.setHeader("Content-Disposition", "attachment;filename="+ URLEncoder.encode("艺人列表.xls", "UTF-8"));
response.setHeader("Connection", "close");
response.setHeader("Content-Type", "application/octet-stream");
workbook.write(response.getOutputStream());
workbook.close();
}
@RequestMapping("/import1")
public Result import1 (MultipartFile impfile, HttpServletResponse response) throws Exception {
// 创建空的工作薄
HSSFWorkbook workbook = new HSSFWorkbook(impfile.getInputStream());
// 获取表
HSSFSheet sheetAt = workbook.getSheetAt(0);
// 获取最后一个交表
int lastRowNum = sheetAt.getLastRowNum();
for (int i = 1; i <=lastRowNum; i++) {
HSSFRow row = sheetAt.getRow(i);
String sid = row.getCell(0).getStringCellValue();
String name = row.getCell(1).getStringCellValue();
String sex = row.getCell(2).getStringCellValue();
int age = (int)row.getCell(3).getNumericCellValue();
String address = row.getCell(4).getStringCellValue();
String zhu = row.getCell(5).getStringCellValue();
String names = row.getCell(6).getStringCellValue();
Student student = new Student();
student.setSid(sid);
student.setName(name);
student.setAddress(address);
student.setAge(age);
student.setZhu(zhu);
student.setSex(sex);
student.setNames(names);
studetnService.add1(student);
}
return new Result(true, MessageConstant.UPLOAD_SUCCESS);
}
}
service:
package com.jiyun.service;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jiyun.entity.PageResult;
import com.jiyun.entity.QueryPageBean;
import com.jiyun.mapper.StudentMapper;
import com.jiyun.pojo.Ke;
import com.jiyun.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
@Service
public class StudetnServiceimpl implements StudetnService {
@Autowired
StudentMapper studentMapper;
@Override
public PageResult findPage(QueryPageBean queryPageBean) {
PageHelper.startPage(queryPageBean.getCurrentPage(), queryPageBean.getPageSize());
List list=studentMapper.findPage(queryPageBean.getQueryString());
// select * from zhongjian z join kew k on z.s_id=k.id where s_id=#{id}
for (Student student : list) {
// 获取学生的id
Integer id = student.getId();
//同过id在去中间表关联查询检查项的信息
List list2=studentMapper.zjianxinag(id);
// 再检查组 中自定义属性
String names= "";
for (Ke ke : list2) {
// 字符串拼接
names+=ke.getMing()+",";
}
//再把这个对象放到检查组自定义的属性
student.setNames(names);
}
PageInfo page = new PageInfo<>(list);
return new PageResult( page.getTotal(),page.getList());
}
@Override
public void add(Student student, Integer[] ids) {
studentMapper.add(student);
Integer id = student.getId();
for (Integer kid : ids) {
studentMapper.zjian(id,kid);
}
}
@Override
public void update(Student student, Integer[] ids) {
studentMapper.update(student);
Integer id = student.getId();
studentMapper.del(id);
for (Integer kid : ids) {
studentMapper.zjian(id,kid);
}
}
@Override
public void del(Integer id) {
studentMapper.del(id);
studentMapper.delAll(id);
}
@Override
public List getid(Integer id) {
return studentMapper.getid(id);
}
@Override
public List fan3() {
return studentMapper.fan3();
}
@Override
public void add1(Student student) {
studentMapper.add1(student);
}
}
定时删除:
package com.jiyun.jobs;
import com.alibaba.fastjson.JSON;
import com.jiyun.pojo.Ke;
import com.jiyun.pojo.Strudent;
import org.springframework.beans.factory.annotation.Autowired;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.util.List;
public class ClearImgJob {
@Autowired
JedisPool jedisPool;
public void clearImg(){
Jedis redis = jedisPool.getResource();
// 读取缓存中的信息
List list = redis.lrange("list", 0, -1);
redis.lpop("list");
redis.close();
redis.lrem("list",0,list.get(1));
在list中名字是小米粒用定时任务删除
// for (int i = 0; i < list.size(); i++) {
// Ke ke = JSON.parseObject(list.get(i), Ke.class);
// if(ke.getName().equals("小米粒")){
// redis.lrem("list",0,list.get(i));
// }
// }
}
}
mapper:
insert into studentw (sid, name, sex, age, address, zhu)
values (#{sid},#{name},#{sex},#{age},#{address},#{zhu})
insert into studentw (sid, name, sex, age, address, zhu)
values (#{sid},#{name},#{sex},#{age},#{address},#{zhu})
insert into zhongjian (s_id,k_id) values (#{sid},#{kid});
update studentw set sid=#{sid}, name=#{name}, sex=#{sex}, age=#{age}, address=#{address}, zhu=#{zhu} where id=#{id}
delete from zhongjian where s_id=#{id}
delete from studentw where id=#{id}
效果展示:
添加:
修改:
统计图:
前端:
传智健康
统计分析会员数量
首页
统计分析
会员数量
饼图:
传智健康
统计分析
会员数量
首页
统计分析
会员数量
controller:
package com.jiyun.controller;
import com.alibaba.dubbo.config.annotation.Reference;
import com.jiyun.entity.Result;
import com.jiyun.pojo.KeVo;
import com.jiyun.service.KeService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("report")
public class tongji {
@Reference
KeService keService;
@RequestMapping("zzt")
public Result zzt(){
List list = keService.findcount1();
List num = new ArrayList<>();
List cname = new ArrayList<>();
Map map = new HashMap<>();
for (KeVo keVo : list) {
num.add(keVo.getNum());
cname.add(keVo.getCname());
}
map.put("num",num);
map.put("cname",cname);
return new Result(true,"显示成功",map);
}
@RequestMapping("bt")
public Result bingzhuangtu(){
List list = keService.findcount1();
List num = new ArrayList<>();
List cname = new ArrayList<>();
List
效果展示:
好文推荐
ssm项目案列总结
ssm项目异常总结
JavaEE项目异常总结
大数据Vue项目异常总结
大数据Vue项目单表案例
如果我的博客对你有帮助,也是你所喜欢的内容,请“点赞” “评论” “收藏” 一键三连,就是对我最大的支持