作者主页:夜未央5788
简介:Java领域优质创作者、Java项目、学习资料、技术互助
文末获取源码
项目介绍
SSM博客管理系统
角色:管理员、博主、游客
前台主要功能包括:首页、博客文章列表、论坛交流、系统公告、留言反馈、个人中心;博主登录系统前台后,可进行发布帖子,收藏博文等;
后台主要分为管理员登录与博主登录;
管理员主要功能:首页、个人中心、博主管理、文章分类管理、博客文章管理、论坛交流、留言板管理、系统管理;
博主主要功能:首页、个人中心、博客文章管理(发布、修改、删除等操作)、我的收藏管理;
环境需要
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/8.0等版本均可;
技术栈
后端:SSM(Spring+SpringMVC+Mybatis)
前端:ElementUI+Vue+layui+html+css+js
使用说明
1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
2. 使用IDEA/Eclipse/MyEclipse导入项目,修改配置,运行项目;
3. 将项目中config.properties配置文件中的数据库配置改为自己的配置,然后运行;
前台地址:http://localhost:8080/ssmt2g9v/front/index.html
账号密码:博主1/123456
后台地址:http://localhost:8080/ssmt2g9v/admin/dist/index.html
管理员账号密码:abo/abo
运行截图
前台界面
后台界面
相关代码
BokewenzhangController
package com.controller;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.utils.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;
import com.entity.BokewenzhangEntity;
import com.entity.view.BokewenzhangView;
import com.service.BokewenzhangService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.CommonUtil;
/**
* 博客文章
* 后端接口
* @author
* @email
* @date 2021-04-16 19:51:51
*/
@RestController
@RequestMapping("/bokewenzhang")
public class BokewenzhangController {
@Autowired
private BokewenzhangService bokewenzhangService;
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,BokewenzhangEntity bokewenzhang,
HttpServletRequest request){
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("bozhu")) {
bokewenzhang.setBozhuzhanghao((String)request.getSession().getAttribute("username"));
}
EntityWrapper<BokewenzhangEntity> ew = new EntityWrapper<BokewenzhangEntity>();
PageUtils page = bokewenzhangService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, bokewenzhang), params), params));
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,BokewenzhangEntity bokewenzhang, HttpServletRequest request){
EntityWrapper<BokewenzhangEntity> ew = new EntityWrapper<BokewenzhangEntity>();
PageUtils page = bokewenzhangService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, bokewenzhang), params), params));
return R.ok().put("data", page);
}
/**
* 列表
*/
@RequestMapping("/lists")
public R list( BokewenzhangEntity bokewenzhang){
EntityWrapper<BokewenzhangEntity> ew = new EntityWrapper<BokewenzhangEntity>();
ew.allEq(MPUtil.allEQMapPre( bokewenzhang, "bokewenzhang"));
return R.ok().put("data", bokewenzhangService.selectListView(ew));
}
/**
* 查询
*/
@RequestMapping("/query")
public R query(BokewenzhangEntity bokewenzhang){
EntityWrapper< BokewenzhangEntity> ew = new EntityWrapper< BokewenzhangEntity>();
ew.allEq(MPUtil.allEQMapPre( bokewenzhang, "bokewenzhang"));
BokewenzhangView bokewenzhangView = bokewenzhangService.selectView(ew);
return R.ok("查询博客文章成功").put("data", bokewenzhangView);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
BokewenzhangEntity bokewenzhang = bokewenzhangService.selectById(id);
bokewenzhang.setClicknum(bokewenzhang.getClicknum()+1);
bokewenzhang.setClicktime(new Date());
bokewenzhangService.updateById(bokewenzhang);
return R.ok().put("data", bokewenzhang);
}
/**
* 前端详情
*/
@IgnoreAuth
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
BokewenzhangEntity bokewenzhang = bokewenzhangService.selectById(id);
bokewenzhang.setClicknum(bokewenzhang.getClicknum()+1);
bokewenzhang.setClicktime(new Date());
bokewenzhangService.updateById(bokewenzhang);
return R.ok().put("data", bokewenzhang);
}
/**
* 赞或踩
*/
@RequestMapping("/thumbsup/{id}")
public R thumbsup(@PathVariable("id") String id,String type){
BokewenzhangEntity bokewenzhang = bokewenzhangService.selectById(id);
if(type.equals("1")) {
bokewenzhang.setThumbsupnum(bokewenzhang.getThumbsupnum()+1);
} else {
bokewenzhang.setCrazilynum(bokewenzhang.getCrazilynum()+1);
}
bokewenzhangService.updateById(bokewenzhang);
return R.ok();
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody BokewenzhangEntity bokewenzhang, HttpServletRequest request){
bokewenzhang.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(bokewenzhang);
bokewenzhangService.insert(bokewenzhang);
return R.ok();
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody BokewenzhangEntity bokewenzhang, HttpServletRequest request){
bokewenzhang.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(bokewenzhang);
bokewenzhangService.insert(bokewenzhang);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody BokewenzhangEntity bokewenzhang, HttpServletRequest request){
//ValidatorUtils.validateEntity(bokewenzhang);
bokewenzhangService.updateById(bokewenzhang);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
bokewenzhangService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<BokewenzhangEntity> wrapper = new EntityWrapper<BokewenzhangEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
String tableName = request.getSession().getAttribute("tableName").toString();
if(tableName.equals("bozhu")) {
wrapper.eq("bozhuzhanghao", (String)request.getSession().getAttribute("username"));
}
int count = bokewenzhangService.selectCount(wrapper);
return R.ok().put("count", count);
}
/**
* 前端智能排序
*/
@IgnoreAuth
@RequestMapping("/autoSort")
public R autoSort(@RequestParam Map<String, Object> params,BokewenzhangEntity bokewenzhang, HttpServletRequest request,String pre){
EntityWrapper<BokewenzhangEntity> ew = new EntityWrapper<BokewenzhangEntity>();
Map<String, Object> newMap = new HashMap<String, Object>();
Map<String, Object> param = new HashMap<String, Object>();
Iterator<Map.Entry<String, Object>> it = param.entrySet().iterator();
while (it.hasNext()) {
Map.Entry<String, Object> entry = it.next();
String key = entry.getKey();
String newKey = entry.getKey();
if (pre.endsWith(".")) {
newMap.put(pre + newKey, entry.getValue());
} else if (StringUtils.isEmpty(pre)) {
newMap.put(newKey, entry.getValue());
} else {
newMap.put(pre + "." + newKey, entry.getValue());
}
}
params.put("sort", "clicknum");
params.put("order", "desc");
PageUtils page = bokewenzhangService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, bokewenzhang), params), params));
return R.ok().put("data", page);
}
}
BozhuController
package com.controller;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.utils.ValidatorUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.annotation.IgnoreAuth;
import com.entity.BozhuEntity;
import com.entity.view.BozhuView;
import com.service.BozhuService;
import com.service.TokenService;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.CommonUtil;
/**
* 博主
* 后端接口
* @author
* @email
* @date 2021-04-16 19:51:51
*/
@RestController
@RequestMapping("/bozhu")
public class BozhuController {
@Autowired
private BozhuService bozhuService;
@Autowired
private TokenService tokenService;
/**
* 登录
*/
@IgnoreAuth
@RequestMapping(value = "/login")
public R login(String username, String password, String captcha, HttpServletRequest request) {
BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", username));
if(user==null || !user.getMima().equals(password)) {
return R.error("账号或密码不正确");
}
String token = tokenService.generateToken(user.getId(), username,"bozhu", "博主" );
return R.ok().put("token", token);
}
/**
* 注册
*/
@IgnoreAuth
@RequestMapping("/register")
public R register(@RequestBody BozhuEntity bozhu){
//ValidatorUtils.validateEntity(bozhu);
BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", bozhu.getBozhuzhanghao()));
if(user!=null) {
return R.error("注册用户已存在");
}
Long uId = new Date().getTime();
bozhu.setId(uId);
bozhuService.insert(bozhu);
return R.ok();
}
/**
* 退出
*/
@RequestMapping("/logout")
public R logout(HttpServletRequest request) {
request.getSession().invalidate();
return R.ok("退出成功");
}
/**
* 获取用户的session用户信息
*/
@RequestMapping("/session")
public R getCurrUser(HttpServletRequest request){
Long id = (Long)request.getSession().getAttribute("userId");
BozhuEntity user = bozhuService.selectById(id);
return R.ok().put("data", user);
}
/**
* 密码重置
*/
@IgnoreAuth
@RequestMapping(value = "/resetPass")
public R resetPass(String username, HttpServletRequest request){
BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", username));
if(user==null) {
return R.error("账号不存在");
}
user.setMima("123456");
bozhuService.updateById(user);
return R.ok("密码已重置为:123456");
}
/**
* 后端列表
*/
@RequestMapping("/page")
public R page(@RequestParam Map<String, Object> params,BozhuEntity bozhu,
HttpServletRequest request){
EntityWrapper<BozhuEntity> ew = new EntityWrapper<BozhuEntity>();
PageUtils page = bozhuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, bozhu), params), params));
return R.ok().put("data", page);
}
/**
* 前端列表
*/
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params,BozhuEntity bozhu, HttpServletRequest request){
EntityWrapper<BozhuEntity> ew = new EntityWrapper<BozhuEntity>();
PageUtils page = bozhuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, bozhu), params), params));
return R.ok().put("data", page);
}
/**
* 列表
*/
@RequestMapping("/lists")
public R list( BozhuEntity bozhu){
EntityWrapper<BozhuEntity> ew = new EntityWrapper<BozhuEntity>();
ew.allEq(MPUtil.allEQMapPre( bozhu, "bozhu"));
return R.ok().put("data", bozhuService.selectListView(ew));
}
/**
* 查询
*/
@RequestMapping("/query")
public R query(BozhuEntity bozhu){
EntityWrapper< BozhuEntity> ew = new EntityWrapper< BozhuEntity>();
ew.allEq(MPUtil.allEQMapPre( bozhu, "bozhu"));
BozhuView bozhuView = bozhuService.selectView(ew);
return R.ok("查询博主成功").put("data", bozhuView);
}
/**
* 后端详情
*/
@RequestMapping("/info/{id}")
public R info(@PathVariable("id") Long id){
BozhuEntity bozhu = bozhuService.selectById(id);
return R.ok().put("data", bozhu);
}
/**
* 前端详情
*/
@RequestMapping("/detail/{id}")
public R detail(@PathVariable("id") Long id){
BozhuEntity bozhu = bozhuService.selectById(id);
return R.ok().put("data", bozhu);
}
/**
* 后端保存
*/
@RequestMapping("/save")
public R save(@RequestBody BozhuEntity bozhu, HttpServletRequest request){
bozhu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(bozhu);
BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", bozhu.getBozhuzhanghao()));
if(user!=null) {
return R.error("用户已存在");
}
bozhu.setId(new Date().getTime());
bozhuService.insert(bozhu);
return R.ok();
}
/**
* 前端保存
*/
@RequestMapping("/add")
public R add(@RequestBody BozhuEntity bozhu, HttpServletRequest request){
bozhu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
//ValidatorUtils.validateEntity(bozhu);
BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", bozhu.getBozhuzhanghao()));
if(user!=null) {
return R.error("用户已存在");
}
bozhu.setId(new Date().getTime());
bozhuService.insert(bozhu);
return R.ok();
}
/**
* 修改
*/
@RequestMapping("/update")
public R update(@RequestBody BozhuEntity bozhu, HttpServletRequest request){
//ValidatorUtils.validateEntity(bozhu);
bozhuService.updateById(bozhu);//全部更新
return R.ok();
}
/**
* 删除
*/
@RequestMapping("/delete")
public R delete(@RequestBody Long[] ids){
bozhuService.deleteBatchIds(Arrays.asList(ids));
return R.ok();
}
/**
* 提醒接口
*/
@RequestMapping("/remind/{columnName}/{type}")
public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
@PathVariable("type") String type,@RequestParam Map<String, Object> map) {
map.put("column", columnName);
map.put("type", type);
if(type.equals("2")) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar c = Calendar.getInstance();
Date remindStartDate = null;
Date remindEndDate = null;
if(map.get("remindstart")!=null) {
Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindStart);
remindStartDate = c.getTime();
map.put("remindstart", sdf.format(remindStartDate));
}
if(map.get("remindend")!=null) {
Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
c.setTime(new Date());
c.add(Calendar.DAY_OF_MONTH,remindEnd);
remindEndDate = c.getTime();
map.put("remindend", sdf.format(remindEndDate));
}
}
Wrapper<BozhuEntity> wrapper = new EntityWrapper<BozhuEntity>();
if(map.get("remindstart")!=null) {
wrapper.ge(columnName, map.get("remindstart"));
}
if(map.get("remindend")!=null) {
wrapper.le(columnName, map.get("remindend"));
}
int count = bozhuService.selectCount(wrapper);
return R.ok().put("count", count);
}
}
如果也想学习本系统,下面领取。关注并回复:307ssm