博客论坛系统
一、项目演示
博客论坛系统
二、项目介绍
基于springboot+vue的前后端分离博客论坛系统
系统角色:管理员、用户
管理员:登录、首页、随笔、留言、评论、搜索、后台首页、角色管理、菜单管理、参数设置、通知公告、文章管理、随笔管理、分类管理、标签管理、留言管理、评论管理、文件管理
用户:注册、登录、首页、随笔、留言、评论、搜索、后台首页、通知公告、文章管理、随笔管理、留言管理、评论管理
项目技术
语言:java
前端技术:Vue、Ruoyi、ElementUI
后端技术:SpringBoot、Mybatis、Redis
数据库:MySQL
三、部分功能截图
四、部分代码展示
package com.ruoyi.web.controller.system;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.lang3.ArrayUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDept;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.service.ISysDeptService;
/**
* 部门信息
*
* @author ruoyi
*/
@RestController
@RequestMapping("/system/dept")
public class SysDeptController extends BaseController
{
@Autowired
private ISysDeptService deptService;
/**
* 获取部门列表
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list")
public AjaxResult list(SysDept dept)
{
List<SysDept> depts = deptService.selectDeptList(dept);
return AjaxResult.success(depts);
}
/**
* 查询部门列表(排除节点)
*/
@PreAuthorize("@ss.hasPermi('system:dept:list')")
@GetMapping("/list/exclude/{deptId}")
public AjaxResult excludeChild(@PathVariable(value = "deptId", required = false) Long deptId)
{
List<SysDept> depts = deptService.selectDeptList(new SysDept());
Iterator<SysDept> it = depts.iterator();
while (it.hasNext())
{
SysDept d = (SysDept) it.next();
if (d.getDeptId().intValue() == deptId
|| ArrayUtils.contains(StringUtils.split(d.getAncestors(), ","), deptId + ""))
{
it.remove();
}
}
return AjaxResult.success(depts);
}
/**
* 根据部门编号获取详细信息
*/
@PreAuthorize("@ss.hasPermi('system:dept:query')")
@GetMapping(value = "/{deptId}")
public AjaxResult getInfo(@PathVariable Long deptId)
{
deptService.checkDeptDataScope(deptId);
return AjaxResult.success(deptService.selectDeptById(deptId));
}
/**
* 获取部门下拉树列表
*/
@GetMapping("/treeselect")
public AjaxResult treeselect(SysDept dept)
{
List<SysDept> depts = deptService.selectDeptList(dept);
return AjaxResult.success(deptService.buildDeptTreeSelect(depts));
}
/**
* 加载对应角色部门列表树
*/
@GetMapping(value = "/roleDeptTreeselect/{roleId}")
public AjaxResult roleDeptTreeselect(@PathVariable("roleId") Long roleId)
{
List<SysDept> depts = deptService.selectDeptList(new SysDept());
AjaxResult ajax = AjaxResult.success();
ajax.put("checkedKeys", deptService.selectDeptListByRoleId(roleId));
ajax.put("depts", deptService.buildDeptTreeSelect(depts));
return ajax;
}
/**
* 新增部门
*/
@PreAuthorize("@ss.hasPermi('system:dept:add')")
@Log(title = "部门管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@Validated @RequestBody SysDept dept)
{
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
return AjaxResult.error("新增部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
dept.setCreateBy(getUsername());
return toAjax(deptService.insertDept(dept));
}
/**
* 修改部门
*/
@PreAuthorize("@ss.hasPermi('system:dept:edit')")
@Log(title = "部门管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@Validated @RequestBody SysDept dept)
{
if (UserConstants.NOT_UNIQUE.equals(deptService.checkDeptNameUnique(dept)))
{
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,部门名称已存在");
}
else if (dept.getParentId().equals(dept.getDeptId()))
{
return AjaxResult.error("修改部门'" + dept.getDeptName() + "'失败,上级部门不能是自己");
}
else if (StringUtils.equals(UserConstants.DEPT_DISABLE, dept.getStatus())
&& deptService.selectNormalChildrenDeptById(dept.getDeptId()) > 0)
{
return AjaxResult.error("该部门包含未停用的子部门!");
}
dept.setUpdateBy(getUsername());
return toAjax(deptService.updateDept(dept));
}
/**
* 删除部门
*/
@PreAuthorize("@ss.hasPermi('system:dept:remove')")
@Log(title = "部门管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{deptId}")
public AjaxResult remove(@PathVariable Long deptId)
{
if (deptService.hasChildByDeptId(deptId))
{
return AjaxResult.error("存在下级部门,不允许删除");
}
if (deptService.checkDeptExistUser(deptId))
{
return AjaxResult.error("部门存在用户,不允许删除");
}
return toAjax(deptService.deleteDeptById(deptId));
}
}
package com.ruoyi.cms.blog.controller;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.cms.fileInfo.service.ISysFileInfoService;
import com.ruoyi.cms.tag.domain.CmsTag;
import com.ruoyi.cms.tag.service.ICmsTagService;
import com.ruoyi.cms.type.domain.CmsType;
import com.ruoyi.cms.type.service.ICmsTypeService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.SysPermissionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cms.blog.domain.CmsBlog;
import com.ruoyi.cms.blog.service.ICmsBlogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
/**
* 文章管理Controller
*
* @author ning
* @date 2022-01-01
*/
@RestController
@RequestMapping("/cms/blog")
public class CmsBlogController extends BaseController
{
@Autowired
private ICmsBlogService cmsBlogService;
@Autowired
private ICmsTypeService cmsTypeService;
@Autowired
private ICmsTagService cmsTagService;
@Autowired
private SysPermissionService permissionService;
@Autowired
private ISysFileInfoService sysFileInfoService;
/**
* 首页查询文章列表
*/
@GetMapping("/cms/cmsList")
public TableDataInfo cmsList(CmsBlog cmsBlog)
{
startPage();
//状态为发布
cmsBlog.setStatus("1");
List<CmsBlog> list = cmsBlogService.selectCmsBlogList(cmsBlog);
return getDataTable(list);
}
/**
* 首页获取文章详细信息
*/
@GetMapping(value = { "/cms/detail/", "/cms/detail/{id}" })
public AjaxResult getInfoDetail(@PathVariable(value = "id", required = false) Long id)
{
AjaxResult ajax = AjaxResult.success();
CmsType cmsType = new CmsType();
CmsTag cmsTag = new CmsTag();
ajax.put("types", cmsTypeService.selectCmsTypeList(cmsType));
ajax.put("tags", cmsTagService.selectCmsTagList(cmsTag));
if (StringUtils.isNotNull(id))
{
ajax.put(AjaxResult.DATA_TAG, cmsBlogService.selectCmsBlogById(id));
}
return ajax;
}
/**
* 首页按分类查询文章列表
*/
@GetMapping("/cms/cmsListByType/{id}")
public TableDataInfo cmsListByTypeId(@PathVariable(value = "id", required = false) Long id)
{
startPage();
List<CmsBlog> list = cmsBlogService.selectCmsBlogListByTypeId(id);
return getDataTable(list);
}
/**
* 首页按标签查询文章列表
*/
@GetMapping("/cms/cmsListByTag/{id}")
public TableDataInfo cmsListByTagId(@PathVariable(value = "id", required = false) Long id)
{
startPage();
List<CmsBlog> list = cmsBlogService.selectCmsBlogListByTagId(id);
return getDataTable(list);
}
/**
* 首页查询推荐文章列表
*/
@GetMapping("/cms/cmsListRecommend")
public TableDataInfo cmsListRecommend(CmsBlog cmsBlog)
{
startPage();
//状态为发布
cmsBlog.setStatus("1");
List<CmsBlog> list = cmsBlogService.selectCmsBlogListRecommend(cmsBlog);
return getDataTable(list);
}
/**
* 首页增加阅读量
*/
@GetMapping("/cms/addBlogViews/{id}")
public AjaxResult addBlogViews(@PathVariable(value = "id", required = false) Long id)
{
CmsBlog cmsBlog = cmsBlogService.selectCmsBlogById(id);
Long views = cmsBlog.getViews();
views+=Long.parseLong("1");
cmsBlog.setViews(views);
cmsBlogService.updateCmsBlog(cmsBlog);
return AjaxResult.success(id);
}
/**
* 随笔页查询文章列表
*/
@GetMapping("/cms/cmsEssayList")
public TableDataInfo cmsEssayList(CmsBlog cmsBlog)
{
startPage();
//状态为发布
cmsBlog.setStatus("1");
List<CmsBlog> list = cmsBlogService.selectCmsBlogList(cmsBlog);
return getDataTable(list);
}
/**
* 查询文章管理列表
*/
@PreAuthorize("@ss.hasPermi('cms:blog:list')")
@GetMapping("/list")
public TableDataInfo list(CmsBlog cmsBlog)
{
startPage();
// 角色集合
Set<String> roles = permissionService.getRolePermission(getLoginUser().getUser());
if (!SecurityUtils.isAdmin(getUserId())&&!roles.contains("admin")&&!roles.contains("cms")){
cmsBlog.setCreateBy(getUsername());
}
List<CmsBlog> list = cmsBlogService.selectCmsBlogList(cmsBlog);
return getDataTable(list);
}
/**
* 导出文章管理列表
*/
@PreAuthorize("@ss.hasPermi('cms:blog:export')")
@Log(title = "文章管理", businessType = BusinessType.EXPORT)
@PostMapping("/export")
public void export(HttpServletResponse response, CmsBlog cmsBlog)
{
List<CmsBlog> list = cmsBlogService.selectCmsBlogList(cmsBlog);
ExcelUtil<CmsBlog> util = new ExcelUtil<CmsBlog>(CmsBlog.class);
util.exportExcel(response, list, "文章管理数据");
}
/**
* 获取文章管理详细信息
*/
@PreAuthorize("@ss.hasPermi('cms:blog:query')")
@GetMapping(value = { "/", "/{id}" })
public AjaxResult getInfo(@PathVariable(value = "id", required = false) Long id)
{
AjaxResult ajax = AjaxResult.success();
CmsType cmsType = new CmsType();
CmsTag cmsTag = new CmsTag();
ajax.put("types", cmsTypeService.selectCmsTypeList(cmsType));
ajax.put("tags", cmsTagService.selectCmsTagList(cmsTag));
if (StringUtils.isNotNull(id))
{
ajax.put(AjaxResult.DATA_TAG, cmsBlogService.selectCmsBlogById(id));
}
return ajax;
}
/**
* 新增文章管理
*/
@PreAuthorize("@ss.hasPermi('cms:blog:add')")
@Log(title = "文章管理", businessType = BusinessType.INSERT)
@PostMapping
public AjaxResult add(@RequestBody CmsBlog cmsBlog)
{
cmsBlog.setCreateBy(getUsername());
Long blogId = cmsBlogService.insertCmsBlog(cmsBlog);
if (blogId==null){
return AjaxResult.error();
}
return AjaxResult.success(blogId);
}
/**
* 修改文章管理
*/
@PreAuthorize("@ss.hasPermi('cms:blog:edit')")
@Log(title = "文章管理", businessType = BusinessType.UPDATE)
@PutMapping
public AjaxResult edit(@RequestBody CmsBlog cmsBlog)
{
cmsBlog.setUpdateBy(getUsername());
//删除原首图
CmsBlog oldBlog = cmsBlogService.selectCmsBlogById(cmsBlog.getId());
if (cmsBlog.getBlogPic().isEmpty()||!cmsBlog.getBlogPic().equals(oldBlog.getBlogPic())){
if(!oldBlog.getBlogPic().isEmpty()){
String blogPic = oldBlog.getBlogPic();
if (blogPic!=null&&!"".equals(blogPic)){
int newFileNameSeparatorIndex = blogPic.lastIndexOf("/");
String FileName = blogPic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
}
}
}
return toAjax(cmsBlogService.updateCmsBlog(cmsBlog));
}
/**
* 删除文章管理
*/
@PreAuthorize("@ss.hasPermi('cms:blog:remove')")
@Log(title = "文章管理", businessType = BusinessType.DELETE)
@DeleteMapping("/{ids}")
public AjaxResult remove(@PathVariable Long[] ids)
{
//删除原首图
for (Long id : ids) {
CmsBlog oldBlog = cmsBlogService.selectCmsBlogById(id);
if(!oldBlog.getBlogPic().isEmpty()){
String blogPic = oldBlog.getBlogPic();
if (blogPic!=null&&!"".equals(blogPic)){
int newFileNameSeparatorIndex = blogPic.lastIndexOf("/");
String FileName = blogPic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
}
}
}
return toAjax(cmsBlogService.deleteCmsBlogByIds(ids));
}
/**
* 取消按钮-删除首图
*/
@PreAuthorize("@ss.hasPermi('cms:blog:edit')")
@PostMapping("/cancel")
public AjaxResult cancel(@RequestBody CmsBlog cmsBlog)
{
String blogPic = cmsBlog.getBlogPic();
if (blogPic!=null&&!"".equals(blogPic)){
Long blogId = cmsBlog.getId();
if (blogId==null){
int newFileNameSeparatorIndex = blogPic.lastIndexOf("/");
String FileName = blogPic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
}else {
String Pic = cmsBlogService.selectCmsBlogById(blogId).getBlogPic();
if (!blogPic.equals(Pic)){
int newFileNameSeparatorIndex = blogPic.lastIndexOf("/");
String FileName = blogPic.substring(newFileNameSeparatorIndex + 1).toLowerCase();
sysFileInfoService.deleteSysFileInfoByFileObjectName(FileName);
}
}
}
return toAjax(1);
}
}
package com.ruoyi.system.service.impl;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.service.ISysConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.PostConstruct;
import java.util.Collection;
import java.util.List;
/**
* 参数配置 服务层实现
*
* @author ruoyi
*/
@Service
public class SysConfigServiceImpl implements ISysConfigService
{
@Autowired
private SysConfigMapper configMapper;
@Autowired
private RedisCache redisCache;
/**
* 项目启动时,初始化参数到缓存
*/
@PostConstruct
public void init()
{
loadingConfigCache();
}
/**
* 查询参数配置信息
*
* @param configId 参数配置ID
* @return 参数配置信息
*/
@Override
@DataSource(DataSourceType.MASTER)
public SysConfig selectConfigById(Long configId)
{
SysConfig config = new SysConfig();
config.setConfigId(configId);
return configMapper.selectConfig(config);
}
/**
* 根据键名查询参数配置信息
*
* @param configKey 参数key
* @return 参数键值
*/
@Override
public String selectConfigByKey(String configKey)
{
String configValue = Convert.toStr(redisCache.getCacheObject(getCacheKey(configKey)));
if (StringUtils.isNotEmpty(configValue))
{
return configValue;
}
SysConfig config = new SysConfig();
config.setConfigKey(configKey);
SysConfig retConfig = configMapper.selectConfig(config);
if (StringUtils.isNotNull(retConfig))
{
redisCache.setCacheObject(getCacheKey(configKey), retConfig.getConfigValue());
return retConfig.getConfigValue();
}
return StringUtils.EMPTY;
}
/**
* 获取验证码开关
*
* @return true开启,false关闭
*/
@Override
public boolean selectCaptchaOnOff()
{
String captchaOnOff = selectConfigByKey("sys.account.captchaOnOff");
if (StringUtils.isEmpty(captchaOnOff))
{
return true;
}
return Convert.toBool(captchaOnOff);
}
/**
* 查询参数配置列表
*
* @param config 参数配置信息
* @return 参数配置集合
*/
@Override
public List<SysConfig> selectConfigList(SysConfig config)
{
return configMapper.selectConfigList(config);
}
/**
* 新增参数配置
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public int insertConfig(SysConfig config)
{
int row = configMapper.insertConfig(config);
if (row > 0)
{
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return row;
}
/**
* 修改参数配置
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public int updateConfig(SysConfig config)
{
int row = configMapper.updateConfig(config);
if (row > 0)
{
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
return row;
}
/**
* 批量删除参数信息
*
* @param configIds 需要删除的参数ID
* @return 结果
*/
@Override
public void deleteConfigByIds(Long[] configIds)
{
for (Long configId : configIds)
{
SysConfig config = selectConfigById(configId);
if (StringUtils.equals(UserConstants.YES, config.getConfigType()))
{
throw new ServiceException(String.format("内置参数【%1$s】不能删除 ", config.getConfigKey()));
}
configMapper.deleteConfigById(configId);
redisCache.deleteObject(getCacheKey(config.getConfigKey()));
}
}
/**
* 加载参数缓存数据
*/
@Override
public void loadingConfigCache()
{
List<SysConfig> configsList = configMapper.selectConfigList(new SysConfig());
for (SysConfig config : configsList)
{
redisCache.setCacheObject(getCacheKey(config.getConfigKey()), config.getConfigValue());
}
}
/**
* 清空参数缓存数据
*/
@Override
public void clearConfigCache()
{
Collection<String> keys = redisCache.keys(Constants.SYS_CONFIG_KEY + "*");
redisCache.deleteObject(keys);
}
/**
* 重置参数缓存数据
*/
@Override
public void resetConfigCache()
{
clearConfigCache();
loadingConfigCache();
}
/**
* 校验参数键名是否唯一
*
* @param config 参数配置信息
* @return 结果
*/
@Override
public String checkConfigKeyUnique(SysConfig config)
{
Long configId = StringUtils.isNull(config.getConfigId()) ? -1L : config.getConfigId();
SysConfig info = configMapper.checkConfigKeyUnique(config.getConfigKey());
if (StringUtils.isNotNull(info) && info.getConfigId().longValue() != configId.longValue())
{
return UserConstants.NOT_UNIQUE;
}
return UserConstants.UNIQUE;
}
/**
* 设置cache key
*
* @param configKey 参数键
* @return 缓存键key
*/
private String getCacheKey(String configKey)
{
return Constants.SYS_CONFIG_KEY + configKey;
}
}
五、底部获取项目源码(9.9¥带走)
有问题,或者需要协助调试运行项目的也可以