package com.joycheng.ryan.controller.admin;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.joycheng.ryan.common.LoginSession;
import com.joycheng.ryan.common.ServerLayResult;
import com.joycheng.ryan.entity.Article;
import com.joycheng.ryan.service.LabelService;
import com.joycheng.ryan.entity.Label;
import com.joycheng.ryan.service.ArticleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@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;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
基于springboot2+mybatis+thymeleaf+layui整合开发的在线心理咨询管理系统源码+数据库sq.zip

共846个文件
gif:300个
js:120个
xml:104个

1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 117 浏览量
2023-06-30
11:30:45
上传
评论
收藏 5.97MB ZIP 举报
温馨提示
基于springboot2+mybatis+thymeleaf+layui整合开发的在线心理咨询管理系统源碼.zip 【资源说明】 该项目是个人毕设项目源码,评审分达到95分,都经过严格调试,确保可以运行!放心下载使用。 该项目资源主要针对计算机、自动化等相关专业的学生或从业者下载使用,也可作为期末课程设计、课程大作业、毕业设计等。 具有较高的学习借鉴价值!基础能力强的可以在此基础上修改调整,以实现类似其他功能。 【行环境 】 jdk8+mysql5.7+IntelliJ IDEA+maven 项目技术 spring boot2+mybatis+thymeleaf+layui 数据库文件 doc/xinlidb.sql http://localhost:8080/ 管理后台登录地址 http://localhost:8080/login admin 123456 数据库名:xinlidb
资源推荐
资源详情
资源评论

























收起资源包目录





































































































共 846 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论


manylinux
- 粉丝: 4788
- 资源: 2900
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- Vue开发环境搭建.docx
- 2025-03-18-204030-121388-3sec.wav 2025-03-18-204030-121388-3sec.wav2025-03-18-204030-121388-3sec.wav
- PMSM-电机控制-关于IGBT的失效模式和应对措施
- yelp-2:3.28.1-3.el8.x64-86.rpm.tar.gz
- 组策略综合练习与解析:涵盖运维及网络系统管理国赛题目详解及应用场景
- PMSM-电机控制-IGBT的双脉冲原理分析和详细试验验证方法
- yascreen-devel-1.97-1.el8.x64-86.rpm.tar.gz
- 简要分析IPPROTO-UDP参数
- LCalendar日期日历组件( 新增回调函数)
- 121#西门子S7-200PLC和组态王的教室灯控制系统 ,基于西门子S7-200PLC与组态王的教室灯光智能控制系统设计与实现,基于西门子S7-200PLC与组态王的教室灯光智能控制系统设计与实现
- 2019年-2020年中国高铁站点数据.zip
- PMSM-电机控制-IGBT单管并联技术
- yascreen-1.97-1.el8.x64-86.rpm.tar.gz
- PMSM-电机控制-IGBT有源钳位技术详细介绍
- comsol六方光子晶体TE TM模式 能带及电场仿真 comsol光学仿真 复现Photonic Crystals Molding the Flow of Light 第76页算例 ,COMS
- yarnpkg-1.22.19-2.el8.x64-86.rpm.tar.gz
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制
