源码获取:俺的博客首页 "资源" 里下载!
功能介绍
基于SSM校园心理咨询服务平台系统分为学生、教师、管理员三种角色。
用户角色主要包括用户注册、用户登录、在线咨询、心理测试、论坛交流、账户维护等功能;
教师角色主要包括教师登录、文章管理、在线回复等功能;
管理员角色主要包括学生管理、教师管理、试题库管理、测试分类管理、试卷管理、新闻管理、系统介绍管理、会员评论管理、轮播图管理、友情链接管理、后台用户管理等功能;
最后根据详细设计的结果,运用JavaEE技术平台,使用更灵活的B/S开发模式和经典的SSM组合框架实现系统的MVC分层架构,并结合MySQL数据库实现了大学生心理减压系统的信息化管理。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS;
5.是否Maven项目: 否;查看源码目录中是否包含pom.xml;若包含,则为maven项目,否则为非maven项目
6.数据库:MySql 5.7版本;
技术栈
1. 后端:Spring SpringMVC MyBatis
2. 前端:JSP+bootstrap+jQuery
使用说明
1. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
若为maven项目,导入成功后请执行maven clean;maven install命令,下载所需jar包;
2. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
3. 将项目中db.properties配置文件中的数据库配置改为自己的配置
4. 配置tomcat,然后运行项目,输入localhost:8080/xxx 登录
![](/qrcode.jpg)
用户管理控制层:
@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 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 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;
}
}
源码获取:俺的博客首页 "资源" 里下载!