当前位置:   article > 正文

基于SpringBoot的大学生心理健康管理系统的设计与实现

基于SpringBoot的大学生心理健康管理系统的设计与实现

目录

前言

 一、技术栈

二、系统功能介绍

管理员功能模块的实现

试卷列表

通知信息管理

通知类型管理

三、核心代码

1、登录模块

 2、文件上传模块

3、代码封装

四、系统测试

软件测试

测试环境

测试用例

用户登录测试

添加通知类别测试

测试结果


前言

传统信息的管理大部分依赖于管理人员的手工登记与管理,然而,随着近些年信息技术的迅猛发展,让许多比较老套的信息管理模式进行了更新迭代,试卷信息因为其管理内容繁杂,管理数量繁多导致手工进行处理不能满足广大用户的需求,因此就应运而生出相应的大学生心理健康管理系统。

本大学生心理健康管理系统分为管理员还有用户两个权限,管理员可以管理用户的基本信息内容,可以管理通知信息以及通知的租赁信息,能够与用户进行相互交流等操作,用户可以查看试卷信息,可以查看通知以及查看管理员回复信息等操作。

该大学生心理健康管理系统采用的是WEB应用程序开发中最受欢迎的B/S三层结构模式,使用占用空间小但功能齐全的MySQL数据库进行数据的存储操作,系统开发技术使用到了JSP技术。该大学生心理健康管理系统能够解决许多传统手工操作的难题,比如数据查询耽误时间长,数据管理步骤繁琐等问题。总的来说,大学生心理健康管理系统性能稳定,功能较全,投入运行使用性价比很高。

 一、技术栈

末尾获取源码
SpringBoot+Vue+JS+ jQuery+Ajax...

二、系统功能介绍

管理员功能模块的实现

试卷列表

此页面提供给管理员的功能有:查看试卷、新增试卷、修改试卷、删除试卷等。

 

通知信息管理

管理员可以对前台的注册用户的基本信息进行管理,可以设置注册用户的账号为冻结或者是在用状态,管理员也能选择很多个已经失效的注册用户的信息进行批量删除操作。

通知类型管理

通知类型管理页面显示所有通知类型,在此页面既可以让管理员添加新的通知信息类型,也能对已有的通知类型信息执行编辑更新,失效的通知类型信息也能让管理员快速删除。下图就是通知类型管理页面。

 

三、核心代码

1、登录模块

  1. package com.controller;
  2. import java.util.Arrays;
  3. import java.util.Calendar;
  4. import java.util.Date;
  5. import java.util.Map;
  6. import javax.servlet.http.HttpServletRequest;
  7. import org.springframework.beans.factory.annotation.Autowired;
  8. import org.springframework.stereotype.Controller;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.PathVariable;
  11. import org.springframework.web.bind.annotation.PostMapping;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.ResponseBody;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import com.annotation.IgnoreAuth;
  18. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  19. import com.entity.TokenEntity;
  20. import com.entity.UserEntity;
  21. import com.service.TokenService;
  22. import com.service.UserService;
  23. import com.utils.CommonUtil;
  24. import com.utils.MD5Util;
  25. import com.utils.MPUtil;
  26. import com.utils.PageUtils;
  27. import com.utils.R;
  28. import com.utils.ValidatorUtils;
  29. /**
  30. * 登录相关
  31. */
  32. @RequestMapping("users")
  33. @RestController
  34. public class UserController{
  35. @Autowired
  36. private UserService userService;
  37. @Autowired
  38. private TokenService tokenService;
  39. /**
  40. * 登录
  41. */
  42. @IgnoreAuth
  43. @PostMapping(value = "/login")
  44. public R login(String username, String password, String captcha, HttpServletRequest request) {
  45. UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
  46. if(user==null || !user.getPassword().equals(password)) {
  47. return R.error("账号或密码不正确");
  48. }
  49. String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
  50. return R.ok().put("token", token);
  51. }
  52. /**
  53. * 注册
  54. */
  55. @IgnoreAuth
  56. @PostMapping(value = "/register")
  57. public R register(@RequestBody UserEntity user){
  58. // ValidatorUtils.validateEntity(user);
  59. if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
  60. return R.error("用户已存在");
  61. }
  62. userService.insert(user);
  63. return R.ok();
  64. }
  65. /**
  66. * 退出
  67. */
  68. @GetMapping(value = "logout")
  69. public R logout(HttpServletRequest request) {
  70. request.getSession().invalidate();
  71. return R.ok("退出成功");
  72. }
  73. /**
  74. * 密码重置
  75. */
  76. @IgnoreAuth
  77. @RequestMapping(value = "/resetPass")
  78. public R resetPass(String username, HttpServletRequest request){
  79. UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
  80. if(user==null) {
  81. return R.error("账号不存在");
  82. }
  83. user.setPassword("123456");
  84. userService.update(user,null);
  85. return R.ok("密码已重置为:123456");
  86. }
  87. /**
  88. * 列表
  89. */
  90. @RequestMapping("/page")
  91. public R page(@RequestParam Map<String, Object> params,UserEntity user){
  92. EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
  93. PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
  94. return R.ok().put("data", page);
  95. }
  96. /**
  97. * 列表
  98. */
  99. @RequestMapping("/list")
  100. public R list( UserEntity user){
  101. EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
  102. ew.allEq(MPUtil.allEQMapPre( user, "user"));
  103. return R.ok().put("data", userService.selectListView(ew));
  104. }
  105. /**
  106. * 信息
  107. */
  108. @RequestMapping("/info/{id}")
  109. public R info(@PathVariable("id") String id){
  110. UserEntity user = userService.selectById(id);
  111. return R.ok().put("data", user);
  112. }
  113. /**
  114. * 获取用户的session用户信息
  115. */
  116. @RequestMapping("/session")
  117. public R getCurrUser(HttpServletRequest request){
  118. Long id = (Long)request.getSession().getAttribute("userId");
  119. UserEntity user = userService.selectById(id);
  120. return R.ok().put("data", user);
  121. }
  122. /**
  123. * 保存
  124. */
  125. @PostMapping("/save")
  126. public R save(@RequestBody UserEntity user){
  127. // ValidatorUtils.validateEntity(user);
  128. if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
  129. return R.error("用户已存在");
  130. }
  131. userService.insert(user);
  132. return R.ok();
  133. }
  134. /**
  135. * 修改
  136. */
  137. @RequestMapping("/update")
  138. public R update(@RequestBody UserEntity user){
  139. // ValidatorUtils.validateEntity(user);
  140. userService.updateById(user);//全部更新
  141. return R.ok();
  142. }
  143. /**
  144. * 删除
  145. */
  146. @RequestMapping("/delete")
  147. public R delete(@RequestBody Long[] ids){
  148. userService.deleteBatchIds(Arrays.asList(ids));
  149. return R.ok();
  150. }
  151. }

 2、文件上传模块

  1. package com.controller;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.IOException;
  5. import java.util.Arrays;
  6. import java.util.Date;
  7. import java.util.HashMap;
  8. import java.util.List;
  9. import java.util.Map;
  10. import java.util.Random;
  11. import java.util.UUID;
  12. import org.apache.commons.io.FileUtils;
  13. import org.apache.commons.lang3.StringUtils;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.http.HttpHeaders;
  16. import org.springframework.http.HttpStatus;
  17. import org.springframework.http.MediaType;
  18. import org.springframework.http.ResponseEntity;
  19. import org.springframework.util.ResourceUtils;
  20. import org.springframework.web.bind.annotation.PathVariable;
  21. import org.springframework.web.bind.annotation.RequestBody;
  22. import org.springframework.web.bind.annotation.RequestMapping;
  23. import org.springframework.web.bind.annotation.RequestParam;
  24. import org.springframework.web.bind.annotation.RestController;
  25. import org.springframework.web.multipart.MultipartFile;
  26. import com.annotation.IgnoreAuth;
  27. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  28. import com.entity.ConfigEntity;
  29. import com.entity.EIException;
  30. import com.service.ConfigService;
  31. import com.utils.R;
  32. /**
  33. * 上传文件映射表
  34. */
  35. @RestController
  36. @RequestMapping("file")
  37. @SuppressWarnings({"unchecked","rawtypes"})
  38. public class FileController{
  39. @Autowired
  40. private ConfigService configService;
  41. /**
  42. * 上传文件
  43. */
  44. @RequestMapping("/upload")
  45. public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
  46. if (file.isEmpty()) {
  47. throw new EIException("上传文件不能为空");
  48. }
  49. String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
  50. File path = new File(ResourceUtils.getURL("classpath:static").getPath());
  51. if(!path.exists()) {
  52. path = new File("");
  53. }
  54. File upload = new File(path.getAbsolutePath(),"/upload/");
  55. if(!upload.exists()) {
  56. upload.mkdirs();
  57. }
  58. String fileName = new Date().getTime()+"."+fileExt;
  59. File dest = new File(upload.getAbsolutePath()+"/"+fileName);
  60. file.transferTo(dest);
  61. FileUtils.copyFile(dest, new File("C:\\Users\\Desktop\\jiadian\\springbootl7own\\src\\main\\resources\\static\\upload"+"/"+fileName));
  62. if(StringUtils.isNotBlank(type) && type.equals("1")) {
  63. ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
  64. if(configEntity==null) {
  65. configEntity = new ConfigEntity();
  66. configEntity.setName("faceFile");
  67. configEntity.setValue(fileName);
  68. } else {
  69. configEntity.setValue(fileName);
  70. }
  71. configService.insertOrUpdate(configEntity);
  72. }
  73. return R.ok().put("file", fileName);
  74. }
  75. /**
  76. * 下载文件
  77. */
  78. @IgnoreAuth
  79. @RequestMapping("/download")
  80. public ResponseEntity<byte[]> download(@RequestParam String fileName) {
  81. try {
  82. File path = new File(ResourceUtils.getURL("classpath:static").getPath());
  83. if(!path.exists()) {
  84. path = new File("");
  85. }
  86. File upload = new File(path.getAbsolutePath(),"/upload/");
  87. if(!upload.exists()) {
  88. upload.mkdirs();
  89. }
  90. File file = new File(upload.getAbsolutePath()+"/"+fileName);
  91. if(file.exists()){
  92. /*if(!fileService.canRead(file, SessionManager.getSessionUser())){
  93. getResponse().sendError(403);
  94. }*/
  95. HttpHeaders headers = new HttpHeaders();
  96. headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
  97. headers.setContentDispositionFormData("attachment", fileName);
  98. return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
  99. }
  100. } catch (IOException e) {
  101. e.printStackTrace();
  102. }
  103. return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
  104. }
  105. }

3、代码封装

  1. package com.utils;
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. /**
  5. * 返回数据
  6. */
  7. public class R extends HashMap<String, Object> {
  8. private static final long serialVersionUID = 1L;
  9. public R() {
  10. put("code", 0);
  11. }
  12. public static R error() {
  13. return error(500, "未知异常,请联系管理员");
  14. }
  15. public static R error(String msg) {
  16. return error(500, msg);
  17. }
  18. public static R error(int code, String msg) {
  19. R r = new R();
  20. r.put("code", code);
  21. r.put("msg", msg);
  22. return r;
  23. }
  24. public static R ok(String msg) {
  25. R r = new R();
  26. r.put("msg", msg);
  27. return r;
  28. }
  29. public static R ok(Map<String, Object> map) {
  30. R r = new R();
  31. r.putAll(map);
  32. return r;
  33. }
  34. public static R ok() {
  35. return new R();
  36. }
  37. public R put(String key, Object value) {
  38. super.put(key, value);
  39. return this;
  40. }
  41. }

四、系统测试

程序软件一旦被开发完成之后,在真正投入日常生活中进行运行使用之前,是必须要经历测试这一个重要的操作环节,因为开发期间注重的是每个单独功能模块的开发,尽管每次开发完成一个单独功能模块时,会通过单元测试进行检验,检验合格才会让程序员继续开发下一个子功能模块,以此类推,当程序员完成所有的系统子功能模块的开发时,这个时候就需要引进系统测试,系统测试就是把所有的子功能模块集成到一起,构建成整个系统,在指定的运行环境下进行运行,主要就是测试系统的所有功能模块在一起是否良好运行,一旦程序软件通过了系统测试这一环节,就意味着它可以进行最终的验收测试了,这个测试步骤的操作用户是程序面向的客户或者是最终用户了。

软件测试

软件测试包括的对象有详细设计,开发出来的软件的运行环境,软件的需求以及软件的源代码内容等,软件测试也包括了五个要素,分别是软件的质量,技术,人员还有流程以及资源这几个要素。软件测试的目标包含了测试的覆盖率信息还有测试效率信息。一般来说,软件测试主要分成了单元测试,集成测试以及系统测试和验收测试这四个阶段的内容,下面将分别进行相关阐述。

单元测试:这个部分需要涉及到程序的代码方面的知识,这个操作环节是程序的开发者进行的,当程序开发者通过代码编写程序的子功能模块时,就会进行单元级别的测试,通常这个环节的测试也会被称作是白盒测试。

集成测试:这个步骤的前提是程序的所有功能模块都已完成开发,这个时候需要把程序所有的子功能模块集成到一起,形成一个完整的系统,此测试的主要目的就是检查这些功能模块集成在一起时的兼容性,也就是检测它们是否按照预期正常运行。

系统测试:当程序测试进入到这个环节时,就意味着程序测试工作已经进行到一半了,这个部分的测试也有另外一个名字,称作是黑盒测试,主要用于测试系统的功能是否按照预期进行运行。

验收测试:开发的程序已经通过了前面的单元测试,集成测试,以及系统测试环节时,就需要进行验收了,这个环节的操作用户就是程序面临的最终用户或者是客户。测试主要目的就是验证开发完成的程序是不是能够符合用户对其的期望,以及程序的所有功能是否符合用户的真正需求。

测试环境

大学生心理健康管理系统的测试选用的测试平台是IDEA平台环境,测试时首先需要用户打开MySQL数据库进行数据库文件的附加操作,然后打开IDEA,选择文件打开网站,把大学生心理健康管理系统的程序添加进入IDEA平台中,接着把文件部署到tomcat服务器里面,最后运行程序,这时用户可以操作系统里面的各个功能,看看程序有没有达到用户的要求。

测试用例

用户登录测试

用户登录需要的信息包含登录名称还有对应密码,输入数据信息都正确了才能进行系统访问处理。用户登录测试过程如表6.1所示:

用户登录测试表

测试目的

操作流程

测试用例

预测结果

测试结果

用户登录

填写用户名密码,点击首页登录按钮

错误填写用户名还有密码

登录失败

提示错误信息

正确填写用户名和密码

登录成功

登录成功

添加通知类别测试

管理员可以在添加通知类别界面输入通知类别名称信息,如果数据信息为空,系统会给出相应提示。只有所有的数据信息都合理输入,管理员才能完成通知类别的添加操作。测试数据见下表:

添加通知类别测试表

测试结果

经过此次对大学生心理健康管理系统的综合性测试,我们不难发现程序的功能并没有出现明显的逻辑性错误,用户在进行功能操作时,程序基本能根据用户操作情况给出相应的反馈。程序质量以及可靠性在系统的反复测试中都经过了严格检验,程序投入生活使用完全没有问题。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/473841
推荐阅读
相关标签
  

闽ICP备14008679号