源码获取:俺的博客首页 "资源" 里下载!
项目介绍
基于SpringBoot Vue的心灵治愈交流平台
角色:管理员、用户、心理咨询师
心灵治愈交流平台 ,在系统首页可以查看首页、系统公告、心理咨询师、心灵专栏、压力测试、小纸条、个人中心、后台管理、聊天等内容
管理员:管理员登录进入心灵治愈交流平台可以查看首页、个人中心、系统公告管理、用户管理、心理咨询师管理、心灵专栏管理、压力测试管理、测试数据管理、咨询师预约管理、小纸条管理、系统管理
用户:用户登录进入心灵治愈交流平台可以查看首页、个人中心、测试数据管理、咨询师预约管理、小纸条管理等内容
心理咨询师: 心理咨询师登录进入心灵治愈交流平台可以查看首页、个人中心、咨询师预约管理、系统管理等内容
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
4.数据库:MySql 5.7/8.0版本均可;
5.是否Maven项目:是;
技术栈
后端:SpringBoot+Mybaits
前端:layui+Vue+ELementUI
使用说明
项目运行:
1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行;
3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;
4. 运行项目,控制台提示运行成功后再去运行前端项目;
5. 管理员用户名密码:admin/admin
普通用户名密码:user/123456
文档介绍详情: 系统性能分析、系统功能分析、系统流程分析、系统设计、系统概要设计、系统结构设计、系统顺序图设计、数据库设计、系统详情设计、前台首页功能模块介绍、管理员功能介绍、用户功能模块、心理咨询师功能模块:
首页详情介绍:
心灵咨询详情介绍:
平台登陆详情入口:
后台管理(个人中心、系统公告管理、用户管理、心理咨询师管理、心灵专栏管理、压力测试管理、测试数据管理、咨询师预约管理、小纸条管理、系统管理):
心灵专栏详情介绍:
咨询师预约详情管理:
登录管理控制器:
/**
* 登入控制器
*/
@Controller
public class LoginController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
//注入
@Autowired
private Producer producer;
@Autowired
private UserService userService;
@RequestMapping("/login")
public String loginView() {
return "admin/login";
}
@ResponseBody
@RequestMapping("/login_do")
public String loginDo(@RequestBody User user, HttpServletRequest request) {
String vrifyCode = (String) request.getSession().getAttribute("vrifyCode");
if (user != null) {
User users = userService.loginByUser(user.getUsername(), user.getPassword());
if (users == null) {
return "passwordError";
} else if (!vrifyCode.equals(user.getVercode())) {
return "vrifyCodeErroe";
}
LoginSession.setUserInSession(users);
request.getSession().setAttribute("loginName", users.getUsername());
return "success";
} else {
return "userNull";
}
}
/**
* 生成验证码
*
* @param httpServletRequest
* @param httpServletResponse
* @throws Exception
*/
@GetMapping("/defaultKaptcha")
public void defaultKaptcha(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
throws Exception {
byte[] captchaChallengeAsJpeg = null;
ByteArrayOutputStream jpegOutputStream = new ByteArrayOutputStream();
try {
//生产验证码字符串并保存到session中
String createText = producer.createText();
httpServletRequest.getSession().setAttribute("vrifyCode", createText);
//使用生产的验证码字符串返回一个BufferedImage对象并转为byte写入到byte数组中
BufferedImage challenge = producer.createImage(createText);
ImageIO.write(challenge, "jpg", jpegOutputStream);
} catch (IllegalArgumentException e) {
httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
//定义response输出类型为image/jpeg类型,使用response输出流输出图片的byte数组
captchaChallengeAsJpeg = jpegOutputStream.toByteArray();
httpServletResponse.setHeader("Cache-Control", "no-store");
httpServletResponse.setHeader("Pragma", "no-cache");
httpServletResponse.setDateHeader("Expires", 0);
httpServletResponse.setContentType("image/jpeg");
ServletOutputStream responseOutputStream =
httpServletResponse.getOutputStream();
responseOutputStream.write(captchaChallengeAsJpeg);
responseOutputStream.flush();
responseOutputStream.close();
}
//注销处理
@RequestMapping("/logout")
public String invalidate(HttpSession session) {
session.invalidate();
return "redirect:login.jsp";
}
}
类描述信息 登入拦截器:
/**
* 类描述信息 登入拦截器
*
*/
public class CheckLoginInterceptor extends HandlerInterceptorAdapter {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//判断用户是否登入
if (LoginSession.getCurrentUser() == null) {
response.sendRedirect("/login");
System.out.println("CheckLoginInterceptor.preHandle" + "----------------未登入------拦截请求--------------->");
return false;
}
return true;
}
}
用户管理详情控制层:
@Controller
public class UserController {
@Autowired
private UserService userService;
@RequestMapping("/userUi")
public String userUI() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/user/userList";
}
@ResponseBody
@RequestMapping("/admin/user/tableList")
public ServerLayResult userList(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit,
@RequestParam(value = "keyword", defaultValue = "") String keyword) {
if (keyword == null || keyword.equals("")) {
//封装Json数据对象
ServerLayResult result = new ServerLayResult(0, "", userService.count(), userService.selectAll(page, limit));
return result;
} else if (keyword != null) {
ServerLayResult result = new ServerLayResult(0, "", userService.selectByUsername(keyword, page, limit).size(),
userService.selectByUsername(keyword, page, limit));
return result;
}
return null;
}
@ResponseBody
@RequestMapping("/admin/user/del")
public Map<String, Object> del(@RequestParam("id") Integer id) {
Map<String, Object> dataMap = new HashMap<>();
Boolean isSuccess = false;
if (id != null && id != 0) {
int del = userService.deleteByPrimaryKey(id);
if (del > 0) {
isSuccess = true;
dataMap.put("success", isSuccess);
return dataMap;
}
}
dataMap.put("success", isSuccess);
return dataMap;
}
/**
* 更新用户信息
*
* @param user
* @return
*/
@ResponseBody
@RequestMapping(value = "/admin/user/update", method = RequestMethod.POST)
public Map<String, Object> updateUser(@RequestBody User user) {
Map<String, Object> dataMap = new HashMap<>();
Boolean isSuccess = false;
if (user != null) {
//根据用户对象的id 查询用户的密码,防止密码丢失
User user1 = userService.selectByPrimaryKey(user.getId());
//再次封装进对象中
if (user1 != null) {
user.setPassword(user1.getPassword());
//更新对象
int update = userService.updateByPrimaryKey(user);
if (update > 0) {
isSuccess = true;
dataMap.put("success", isSuccess);
return dataMap;
}
}
}
dataMap.put("success", isSuccess);
return dataMap;
}
/**
* 重置用户密码
*
* @param id
* @return
*/
@ResponseBody
@RequestMapping("/admin/user/resetPwd")
public Map<String, Object> restPwd(@RequestParam("id") Integer id) {
Map<String, Object> dataMap = new HashMap<>();
Boolean isSuccess = false;
if (id != null && id > 0) {
//根据id查询出用户
User user = userService.selectByPrimaryKey(id);
//开始重置密码,重置密码使用的Spring提供的工具类进行对密码123456进行加密
user.setPassword(DigestUtils.md5DigestAsHex("123456".getBytes()));
//调用更新方法
int restPwd = userService.updateByPrimaryKey(user);
if (restPwd > 0) {
isSuccess = true;
dataMap.put("success", isSuccess);
return dataMap;
}
}
dataMap.put("success", isSuccess);
return dataMap;
}
}
后台文章管理控制层:
@Controller
public class ArticleController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private ArticleService articleService;
@Autowired
private LabelService labelService;
@RequestMapping("/articleUi")
public String articleListUi() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/article/list";
}
@RequestMapping("/articleUiAdd")
public String articleAddUi() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/article/listform";
}
/**
* 后台文章列表
*
* @param page 当前页
* @param limit 每页多少条
* @param keyword1 关键字查询
* @param keyword2
* @param keyword3
* @return
*/
@ResponseBody
@RequestMapping("/admin/article/list")
public ServerLayResult<Article> list(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit,
String keyword1, String keyword2, String keyword3) {
if (keyword1 != null && keyword2 != "" || keyword2 != null && keyword2 != "" || keyword3 != null && keyword3 != "") {
List<Article> articles = articleService.selectByKeyWord(page, limit, keyword1, keyword2, keyword3);
ServerLayResult result = new ServerLayResult(0, "", articles.size(), articles);
return result;
}
//封装数据
ServerLayResult result = new ServerLayResult(0, "", articleService.count(), articleService.selectAll(page, limit));
return result;
}
/**
* 根据ID删除
*
* @param id
* @return
*/
@ResponseBody
@RequestMapping("/admin/article/del")
public Map<String, Object> delArticle(@RequestParam("id") int id) {
Map<String, Object> dataMap = new HashMap<>();
boolean isSuccess = articleService.deleteByPrimaryKey(id);
dataMap.put("success", isSuccess);
return dataMap;
}
/**
* 前台响应json数据
* 解析保存
*
* @param article
* @return
*/
@ResponseBody
@RequestMapping("/admin/article/add")
public Map<String, Object> addArticle(@RequestBody JSONObject article) {
JSONObject json = JSON.parseObject(article.toJSONString());
String author = json.getString("author");
Integer label = json.getInteger("label");
String title = json.getString("title");
String content = json.getString("content");
String status = json.getString("status");
int temp = 0;
if (status != null) {
if (status.equals("on")) {
temp = 1;
}
}
Label label1 = new Label();
label1.setId(label);
Article articles = new Article();
articles.setAuthor(author);
articles.setContent(content);
articles.setTitle(title);
articles.setStatus(temp);
articles.setCreateTime(new Date());
articles.setLabel(label1);
logger.info(article + "");
boolean isSuccess = articleService.insert(articles);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("success", isSuccess);
return dataMap;
}
/**
* 根据前台响应的json对象封装后通过业务方法保存到数据库
*
* @param article
* @return
*/
@ResponseBody
@RequestMapping("/admin/article/update")
public Map<String, Object> updateArticle(@RequestBody JSONObject article) {
JSONObject json = JSON.parseObject(article.toJSONString());
String author = json.getString("author");
Integer label = json.getInteger("label");
Integer id = json.getInteger("id");
String title = json.getString("title");
String content = json.getString("content");
String status = json.getString("status");
int temp = 0;
if (status != null) {
if (status.equals("on")) {
temp = 1;
}
}
Label label1 = new Label();
label1.setId(label);
Article articles = new Article();
articles.setId(id);
articles.setAuthor(author);
articles.setContent(content);
articles.setTitle(title);
articles.setStatus(temp);
articles.setCreateTime(new Date());
articles.setLabel(label1);
logger.info(article + "");
boolean isSuccess = articleService.updateByPrimaryKey(articles);
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("success", isSuccess);
return dataMap;
}
}
后台留言详情控制器:
/**
* 后台留言控制器
*/
@Controller
public class LeacotController {
@Autowired
private LeacotService leacotService;
@Autowired
private ReplyService replyService;
@RequestMapping("/leacotsView")
public String leacotUi() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/leacots/leacotsList";
}
/**
* 用户留言列表
*
* @param page
* @param limit
* @param keyword1
* @return
*/
@ResponseBody
@RequestMapping("/admin/leacots/list")
public ServerLayResult leacotsList(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit, String keyword1) {
if (keyword1 != null) {
List<Leacot> leacots = leacotService.selectByKeyWord(page, limit, keyword1);
ServerLayResult result = new ServerLayResult(0, "", leacots.size(), leacots);
return result;
}
ServerLayResult result = new ServerLayResult(0, "", leacotService
.count(), leacotService.selectAll(page, limit));
return result;
}
/**
* 根据ID删除 并且删除关联
*
* @param id
* @return
*/
@ResponseBody
@RequestMapping("/admin/leacots/del")
public Map<String, Object> del(@RequestParam("id") int id) {
Map<String, Object> dataMap = new HashMap<>();
boolean isSuccess = false;
Leacot leacot = leacotService.selectByPrimaryKey(id);
//删除关联
if (leacot != null) {
boolean delReply = replyService.deleteByPrimaryKey(leacot.getId());
if (delReply) {
boolean delete = leacotService.deleteByPrimaryKey(id);
isSuccess = true;
dataMap.put("success", isSuccess);
return dataMap;
}
}
dataMap.put("success", isSuccess);
return dataMap;
}
/**
* {id: "4", leacotsUser: "test", content: "测试留言内容", replyContent: "fsafsf", status: "on"}
*
* @param json
* @return
*/
@ResponseBody
@RequestMapping("/admin/leacots/update")
public Map<String, Object> update(@RequestBody JSONObject json) {
Map<String, Object> dataMap = new HashMap<>();
boolean isSuccess = false;
JSONObject data = JSON.parseObject(json.toJSONString());
Integer id = data.getInteger("id");
String leacotsUser = data.getString("leacotsUser");
String content = data.getString("content");
//回复内容
String replyContent = data.getString("replyContent");
//回复状态
String status = data.getString("status");
int temp = 0;
if (status != null) {
if (status.equals("on")) {
temp = 1;
}
}
//默认从session获得replyUser
Reply reply = new Reply(id, replyContent, new Date(), "admin");
//更新回复表
boolean updateReply = replyService.updateByPrimaryKey(reply);
Leacot leacot = new Leacot(id, content, new Date(), leacotsUser, reply, temp);
//更新留言表
boolean updateLeacot = leacotService.updateByPrimaryKey(leacot);
if (updateLeacot && updateReply) {
isSuccess = true;
dataMap.put("success", isSuccess);
return dataMap;
}
dataMap.put("success", isSuccess);
return dataMap;
}
}
心理测试详情管理控制器:
/**
* 心理测试控制器
*/
@Controller
public class TopicController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private TopicService topicService;
@RequestMapping("/topicView")
public String topicView() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/topic/topicList";
}
/**
* 题目列表显示和高级查询
*
* @param page
* @param limit
* @param keyword1
* @return
*/
@ResponseBody
@RequestMapping("/admin/topic/list")
public ServerLayResult list(@RequestParam("page") Integer page,
@RequestParam("limit") Integer limit, String keyword1) {
logger.info("高级查询数据======"+keyword1);
if (keyword1 != null) {
List<Topic> topics = topicService.selectByKeyWord(page, limit, keyword1);
ServerLayResult result = new ServerLayResult(0, "", topics.size(), topics);
return result;
}
//封装数据
ServerLayResult result = new ServerLayResult(0, "", topicService.count(), topicService.selectAll(page, limit));
return result;
}
/**
* 根据ID删除
*
* @param id
* @return
*/
@ResponseBody
@RequestMapping("/admin/topic/del")
public Map<String, Object> del(@RequestParam("id") Integer id) {
Map<String, Object> dataMap = new HashMap<>();
boolean delete = topicService.deleteByPrimaryKey(id);
dataMap.put("status", delete);
return dataMap;
}
/**
* 更新
*
* @param topic
* @return
*/
@ResponseBody
@RequestMapping(value = "/admin/topic/update", method = RequestMethod.POST)
public Map<String, Object> update(@RequestBody Topic topic) {
Map<String, Object> dataMap = new HashMap<>();
boolean update = topicService.updateByPrimaryKey(topic);
dataMap.put("status", update);
return dataMap;
}
@ResponseBody
@RequestMapping(value = "/admin/topic/add", method = RequestMethod.POST)
public Map<String, Object> insert(@RequestBody Topic topic) {
Map<String, Object> dataMap = new HashMap<>();
boolean insert = topicService.insert(topic);
dataMap.put("status",insert);
return dataMap;
}
}
源码获取:俺的博客首页 "资源" 里下载!