基于javaweb+mysql的springboot在线心理测评系统设计和实现(java+springboot+ssm+mysql+thymeleaf+html+maven)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot在线心理测评系统设计和实现(java+springboot+ssm+mysql+thymeleaf+html+maven)
一、项目简述
本系统主要实现的功能有: 在线测评,在线留言,在线文章浏览。,在线公告,后台 评论管理,用户管理,测评管理,分值管理,测评结果查 询等等。
二、项目运行
环境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持) 项目技术: Springboot+ SpringMVC + MyBatis + ThymeLeaf + JavaScript + JQuery + Ajax + maven等等
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);
}
//设置用户登入的Session
public static void setUserInSession(User contextUser) {
if (contextUser != null) {
//保存session
getSession().setAttribute(USER_IN_SESSION, contextUser);
} else {
//注销session
getSession().invalidate();
}
}
//共享给外部调用登入session
public static User getCurrentUser() {
return (User) getSession().getAttribute(USER_IN_SESSION);
}
}
/**
* 类描述信息 登入拦截器
*
* @ClassName CheckLoginInterceptor
* @Description: TODO
* @Viersion V1.0.1
*/
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 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
*/
@ResponseBody
@RequestMapping("/admin/pgtest/list")
public ServerLayResult list(@RequestParam("page") int page, @RequestParam("limit") int limit, String keyword1) {
if (keyword1 != null) {
if (keyword1 != null && keyword1 != "") {
List<PgTest> pgTests = pgTestService.selectByKeyWord(page, limit, keyword1);
ServerLayResult result = new ServerLayResult(0, "", pgTests.size(), pgTests);
return result;
}
}
ServerLayResult result = new ServerLayResult(0, "", pgTestService.count(), pgTestService.selectAll(page, limit));
return result;
}
/**
* 根据ID删除评测记录
*
* @param id
* @return
*/
@ResponseBody
@RequestMapping("/admin/pgtest/del")
public Map<String, Object> del(@RequestParam("id") Integer id) {
Map<String, Object> dataMap = new HashMap<>();
boolean delete = pgTestService.deleteByPrimaryKey(id);
dataMap.put("status", delete);
return dataMap;
}
}
/**
public String clientArticleList(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit, Model model) {
PageHelper.startPage(page, limit);
List<Article> articles = articleService.selectClientAll();
PageInfo info = new PageInfo(articles);
model.addAttribute("info", info);
model.addAttribute("articleList", info.getList());
//共享数据
return "client/html/article";
}
/**
* 前台查看文章
* @param id
* @param model
* @return
*/
@RequestMapping("/article/get")
public String clientArticleById(@RequestParam("id") int id, Model model) {
Article article = articleService.selectByPrimaryKey(id);
model.addAttribute("article", article);
int index = 1;
model.addAttribute("index", ++index);
return "client/html/articleDetails";
}
}
/**
* 前端公告
*/
@Controller
public class ClientNoticeController {
@Autowired
private NoticeService noticeService;
@RequestMapping("/noticeClientUi/list")
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 ConsoleController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@RequestMapping("/admin")
public String index() {
logger.info(LoginSession.getCurrentUser().getUsername());
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/index";
}
@RequestMapping("/home/console")
public String console() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/home/console";
}
}
@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<>();
/**
* 前台文章显示
*/
@Controller
public class ClientArticleController {
@Autowired
private ArticleService articleService;
/**
* 前台文章
* @param page
* @param limit
* @param model
* @return
*/
@RequestMapping("/article/list")
public String clientArticleList(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit, Model model) {
PageHelper.startPage(page, limit);
List<Article> articles = articleService.selectClientAll();
PageInfo info = new PageInfo(articles);
model.addAttribute("info", info);
model.addAttribute("articleList", info.getList());
//共享数据
return "client/html/article";
}
/**
* 前台查看文章
* @param id
* @param model
* @return
dataMap.put("status",insert);
return dataMap;
}
}
/**
* 处理测试记录
*/
@Controller
public class PgTestController {
@Autowired
private PgTestService pgTestService;
@RequestMapping("/pgtestView")
public String pgtestView() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/topic/pgtestList";
}
/**
* 列表查询,高级查询
*
//设置用户登入的Session
public static void setUserInSession(User contextUser) {
if (contextUser != null) {
//保存session
getSession().setAttribute(USER_IN_SESSION, contextUser);
} else {
//注销session
getSession().invalidate();
}
}
//共享给外部调用登入session
public static User getCurrentUser() {
return (User) getSession().getAttribute(USER_IN_SESSION);
}
}
/**
* 类描述信息 登入拦截器
*
* @ClassName CheckLoginInterceptor
* @Description: TODO
* @Viersion V1.0.1
*/
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 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";
}
/**
* 用户留言列表
/**
* 前台响应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
*/
/**
* 修改密码
*/
@Controller
public class UpdatePasswordController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private UserService userService;
@RequestMapping("/updatePwdViwe")
public String updatePwd() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/system/pwdUpdate";
}
@ResponseBody
@RequestMapping("/admin/sysPwd/update")
public Map<String, Object> updatePwd(@RequestBody JSONObject json) {
Map<String, Object> dataMap = new HashMap<>();
boolean isSuccess = false;
JSONObject data = JSON.parseObject(json.toJSONString());
String oldPassword = data.getString("oldPassword");
String password = data.getString("password");
String repassword = data.getString("repassword");
logger.info("====>" + oldPassword + "--" + password + "--" + repassword);
//这里默认只能修改管理员密码
User byUsername = userService.getByUsername(LoginSession.getCurrentUser().getUsername());
logger.info("---->" + byUsername);
if (byUsername != null) {
//校验旧密码是否正确
if (!byUsername.getPassword().equals(oldPassword)) {
dataMap.put("scueess", isSuccess);
return dataMap;
}
//校验两次输入的密码是否匹配
if (!password.equals(repassword)) {
dataMap.put("scueess", isSuccess);
/**
* 登入控制器
*/
@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";
}
@RequestMapping("/register")
public String register() {
return "admin/register";
}
@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";
}
}
@ResponseBody
@RequestMapping("/register_do")
public String register(@RequestBody User user, HttpServletRequest request) {
System.out.println("***************");
ServerLayResult result = new ServerLayResult(0, "", noticeService.count(), noticeService.selectAll(page, limit));
return result;
}
/**
* 根据ID删除公告
*
* @param id
* @return
*/
@ResponseBody
@RequestMapping("/admin/notice/del")
public Map<String, Object> delNotice(@RequestParam("id") int id) {
Map<String, Object> dataMap = new HashMap<>();
boolean isSuccess = noticeService.deleteByPrimaryKey(id);
dataMap.put("success", isSuccess);
return dataMap;
}
/**
* 更新公告
*
* @param notice
* @return
*/
@ResponseBody
@RequestMapping("/admin/notice/save")
public Map<String, Object> saveNotice(@RequestBody Notice notice) {
Map<String, Object> dataMap = new HashMap<>();
boolean isSuccess = noticeService.insert(notice);
dataMap.put("success", isSuccess);
return dataMap;
}
@ResponseBody
@RequestMapping("/admin/notice/update")
public Map<String, Object> updateNotice(@RequestBody Notice notice) {
Map<String, Object> dataMap = new HashMap<>();
boolean isSuccess = noticeService.updateByPrimaryKey(notice);
dataMap.put("success", isSuccess);
return dataMap;
}
}
}
mapData.put("status", false);
return mapData;
}
}
/**
* 用户留言
*/
@Controller
public class ClientLeacotsController {
@Autowired
private LeacotService leacotService;
@Autowired
private ReplyService replyService;
/**
* 留言列表
*
* @param page
* @param limit
* @param model
* @return
* @param page
* @param limit
* @param model
* @return
*/
@RequestMapping("/article/list")
public String clientArticleList(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "limit", defaultValue = "10") Integer limit, Model model) {
PageHelper.startPage(page, limit);
List<Article> articles = articleService.selectClientAll();
PageInfo info = new PageInfo(articles);
model.addAttribute("info", info);
model.addAttribute("articleList", info.getList());
//共享数据
return "client/html/article";
}
/**
* 前台查看文章
* @param id
* @param model
* @return
*/
@RequestMapping("/article/get")
public String clientArticleById(@RequestParam("id") int id, Model model) {
Article article = articleService.selectByPrimaryKey(id);
model.addAttribute("article", article);
int index = 1;
model.addAttribute("index", ++index);
return "client/html/articleDetails";
}
}
/**
* 公告管理
*/
@Controller
public class NoticeController {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@Autowired
private NoticeService noticeService;
@RequestMapping("/noticeUi")
public String articleListUi() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/notice/noticeList";
}
@RequestMapping("/noticeUiAdd")
public String articleAddUi() {
if (!LoginSession.getCurrentUser().getUsername().equals("admin")) {
return "client/html/index";
}
return "admin/notice/noticeAdd";
}
/**
* 高级查询公告列表