• SpringBoot+Vue项目校园博客系统


    文末获取源码

    开发语言:Java

    开发工具:IDEA /Eclipse

    数据库:MYSQL5.7

    使用框架:springboot+vue

    JDK版本:jdk1.8

    前言介绍 

    随着现在网络的快速发展,网上管理系统也逐渐快速发展起来,网上管理模式很快融入到了许多网站的之中,随之就产生了“校园博客系统”,这样就让校园博客系统更加方便简单。

    对于本校园博客系统的设计来说,系统开发主要是采用java语言技术,在整个系统的设计中应用MySQL数据库来完成数据存储,具体根据校园博客系统的现状来进行开发的,具体根据现实的需求来实现校园博客系统网络化的管理,各类信息有序地进行存储,进入校园博客系统页面之后,方可开始操作主控界面,主要功能包括管理员:首页、个人中心、博主管理、文章分类管理、文章信息管理、举报投诉管理、系统管理,博主;首页、个人中心、文章信息管理、举报投诉管理、我的收藏管理,前台首页;首页、文章信息、系统公告、个人中心、后台管理、在线客服等功能。

    系统功能需求分析 

    对于一个新的网站来说开发新网站我们就要做出这个系统的任务需求分析,因为对系统分析的质量好坏它可以决定这个网站开发的意义,俗话说得好一个好的开头是成功的一半,对于开发这个校园博客系统来说前期的分析是比较重要的,所以任务分析它可以决定这系统的开展和设计,这样就可以保证博主满意性。

    任务的需求它能决定这个系统开发过程当中一个重要环节,所以我们在系统开发过程所用质量是比较重要的,因为我们在系统应用过程当中不一定那会出现问题,所以我们在进行对系统分析是比较重要的,因为它可以决定这个系统功能和需求。

    本课题要求实现一套校园博客系统的开发与实现,主要实现功能包括管理员:首页、个人中心、博主管理、文章分类管理、文章信息管理、举报投诉管理、系统管理,博主;首页、个人中心、文章信息管理、举报投诉管理、我的收藏管理。

    (1)管理员用例需求如图

    博主用例需求如图

    系统的功能结构图 

    通过系统需求分析,本校园博客系统的功能结构设计如图

    系统功能实现 

    前台首页功能实现

    校园博客系统,在系统首页可以查看首页、文章信息、系统公告、个人中心、后台管理、在线客服等内容,如图

    博主注册,在注册页面通过查看博主账号、密码、博主姓名、性别、年龄、手机、邮箱等内容进行注册,如图 

    博主登录,在登录页面通过填写账号、密码等信息进行登录,如图

     

    个人中心,在个人中心页面中可以查看博主账号、博主姓名、头像、性别、年龄、手机、邮箱等信息进行更新信息、退出登录,如图

     

    文章信息,在文章信息页面中可以查看文章标题、分类、图片、发布日期、博主账号、邮箱、点击次数等详细信息进行点我收藏,如图

     

    文章信息界面图 

     

    系统公告

     

    管理员登录

    管理员登录,通过填写用户名、密码、角色等信息,输入完成后选择登录即可进入校园博客系统,如图 

     

    管理员对博主管理获取博主账号、博主姓名、头像、性别、年龄、手机、邮箱并进行详情、删除、修改。博主管理效果图如图

     

    管理员对文章分类管理查看分类等信息进行详情、删除、修改操作。文章分类管理效果图如图

     

    管理员对文章信息管理进行编辑文章标题、分类、图片、发布日期、博主账号、邮箱等信息进行详情、删除、修改操作。文章信息管理效果图如图 

     

    管理员对举报投诉管理进行编辑标题、类型、图片、举报内容、举报时间、博主账号、手机、审核回复、审核状态、审核等信息进行详情、删除、修改操作。举报投诉管理效果图如图

     

    轮播图;该页面为轮播图管理界面。管理员可以在此页面进行首页轮播图的管理,通过新建操作可在轮播图中加入新的图片,还可以对以上传的图片进行修改操作,以及图片的删除操作。轮播图管理效果图如图

     

    管理员对系统公告进行编辑标题、简介、图片等信息进行详情、删除、修改操作。系统公告效果图如图

     

    博主功能实现

    校园博客系统,在系统可以查看首页、个人中心、文章信息管理、举报投诉管理、我的收藏管理等内容,如图

     

    博主对举报投诉管理进行查看标题、类型、图片、举报内容、举报时间、博主账号、手机、审核回复、审核状态、审核并进行详情、修改操作,如图

    我的收藏管理进行查看收藏名称、收藏图片并进行详情、删除操作如图

     

     部分核心代码:   

    数据库连接信息

    1. # Tomcat
    2. server:
    3. tomcat:
    4. uri-encoding: UTF-8
    5. port: 8080
    6. servlet:
    7. context-path: /springboot60zv5
    8. spring:
    9. datasource:
    10. driverClassName: com.mysql.jdbc.Driver
    11. url: jdbc:mysql://127.0.0.1:3306/springboot60zv5?useUnicode=true&characterEncoding=utf-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=GMT%2B8
    12. username: root
    13. password: 123456
    14. # driverClassName: com.microsoft.sqlserver.jdbc.SQLServerDriver
    15. # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=springboot60zv5
    16. # username: sa
    17. # password: 123456
    18. servlet:
    19. multipart:
    20. max-file-size: 10MB
    21. max-request-size: 10MB
    22. resources:
    23. static-locations: classpath:static/,file:static/
    24. #mybatis
    25. mybatis-plus:
    26. mapper-locations: classpath*:mapper/*.xml
    27. #实体扫描,多个package用逗号或者分号分隔
    28. typeAliasesPackage: com.entity
    29. global-config:
    30. #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
    31. id-type: 1
    32. #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
    33. field-strategy: 2
    34. #驼峰下划线转换
    35. db-column-underline: true
    36. #刷新mapper 调试神器
    37. refresh-mapper: true
    38. #逻辑删除配置
    39. logic-delete-value: -1
    40. logic-not-delete-value: 0
    41. #自定义SQL注入器
    42. sql-injector: com.baomidou.mybatisplus.mapper.LogicSqlInjector
    43. configuration:
    44. map-underscore-to-camel-case: true
    45. cache-enabled: false
    46. call-setters-on-nulls: true
    47. #springboot 项目mybatis plus 设置 jdbcTypeForNull (oracle数据库需配置JdbcType.NULL, 默认是Other)
    48. jdbc-type-for-null: 'null'

    控制层(controller)

    1. /**
    2. * 博主
    3. * 后端接口
    4. * @author
    5. * @email
    6. * @date 2021-03-15 19:54:47
    7. */
    8. @RestController
    9. @RequestMapping("/bozhu")
    10. public class BozhuController {
    11. @Autowired
    12. private BozhuService bozhuService;
    13. @Autowired
    14. private TokenService tokenService;
    15. /**
    16. * 登录
    17. */
    18. @IgnoreAuth
    19. @RequestMapping(value = "/login")
    20. public R login(String username, String password, String captcha, HttpServletRequest request) {
    21. BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", username));
    22. if(user==null || !user.getMima().equals(password)) {
    23. return R.error("账号或密码不正确");
    24. }
    25. String token = tokenService.generateToken(user.getId(), username,"bozhu", "博主" );
    26. return R.ok().put("token", token);
    27. }
    28. /**
    29. * 注册
    30. */
    31. @IgnoreAuth
    32. @RequestMapping("/register")
    33. public R register(@RequestBody BozhuEntity bozhu){
    34. //ValidatorUtils.validateEntity(bozhu);
    35. BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", bozhu.getBozhuzhanghao()));
    36. if(user!=null) {
    37. return R.error("注册用户已存在");
    38. }
    39. Long uId = new Date().getTime();
    40. bozhu.setId(uId);
    41. bozhuService.insert(bozhu);
    42. return R.ok();
    43. }
    44. /**
    45. * 退出
    46. */
    47. @RequestMapping("/logout")
    48. public R logout(HttpServletRequest request) {
    49. request.getSession().invalidate();
    50. return R.ok("退出成功");
    51. }
    52. /**
    53. * 获取用户的session用户信息
    54. */
    55. @RequestMapping("/session")
    56. public R getCurrUser(HttpServletRequest request){
    57. Long id = (Long)request.getSession().getAttribute("userId");
    58. BozhuEntity user = bozhuService.selectById(id);
    59. return R.ok().put("data", user);
    60. }
    61. /**
    62. * 密码重置
    63. */
    64. @IgnoreAuth
    65. @RequestMapping(value = "/resetPass")
    66. public R resetPass(String username, HttpServletRequest request){
    67. BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", username));
    68. if(user==null) {
    69. return R.error("账号不存在");
    70. }
    71. user.setMima("123456");
    72. bozhuService.updateById(user);
    73. return R.ok("密码已重置为:123456");
    74. }
    75. /**
    76. * 后端列表
    77. */
    78. @RequestMapping("/page")
    79. public R page(@RequestParam Map<String, Object> params,BozhuEntity bozhu,
    80. HttpServletRequest request){
    81. EntityWrapper<BozhuEntity> ew = new EntityWrapper<BozhuEntity>();
    82. PageUtils page = bozhuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, bozhu), params), params));
    83. return R.ok().put("data", page);
    84. }
    85. /**
    86. * 前端列表
    87. */
    88. @RequestMapping("/list")
    89. public R list(@RequestParam Map<String, Object> params,BozhuEntity bozhu, HttpServletRequest request){
    90. EntityWrapper<BozhuEntity> ew = new EntityWrapper<BozhuEntity>();
    91. PageUtils page = bozhuService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.likeOrEq(ew, bozhu), params), params));
    92. return R.ok().put("data", page);
    93. }
    94. /**
    95. * 列表
    96. */
    97. @RequestMapping("/lists")
    98. public R list( BozhuEntity bozhu){
    99. EntityWrapper<BozhuEntity> ew = new EntityWrapper<BozhuEntity>();
    100. ew.allEq(MPUtil.allEQMapPre( bozhu, "bozhu"));
    101. return R.ok().put("data", bozhuService.selectListView(ew));
    102. }
    103. /**
    104. * 查询
    105. */
    106. @RequestMapping("/query")
    107. public R query(BozhuEntity bozhu){
    108. EntityWrapper< BozhuEntity> ew = new EntityWrapper< BozhuEntity>();
    109. ew.allEq(MPUtil.allEQMapPre( bozhu, "bozhu"));
    110. BozhuView bozhuView = bozhuService.selectView(ew);
    111. return R.ok("查询博主成功").put("data", bozhuView);
    112. }
    113. /**
    114. * 后端详情
    115. */
    116. @RequestMapping("/info/{id}")
    117. public R info(@PathVariable("id") Long id){
    118. BozhuEntity bozhu = bozhuService.selectById(id);
    119. return R.ok().put("data", bozhu);
    120. }
    121. /**
    122. * 前端详情
    123. */
    124. @RequestMapping("/detail/{id}")
    125. public R detail(@PathVariable("id") Long id){
    126. BozhuEntity bozhu = bozhuService.selectById(id);
    127. return R.ok().put("data", bozhu);
    128. }
    129. /**
    130. * 后端保存
    131. */
    132. @RequestMapping("/save")
    133. public R save(@RequestBody BozhuEntity bozhu, HttpServletRequest request){
    134. bozhu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
    135. //ValidatorUtils.validateEntity(bozhu);
    136. BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", bozhu.getBozhuzhanghao()));
    137. if(user!=null) {
    138. return R.error("用户已存在");
    139. }
    140. bozhu.setId(new Date().getTime());
    141. bozhuService.insert(bozhu);
    142. return R.ok();
    143. }
    144. /**
    145. * 前端保存
    146. */
    147. @RequestMapping("/add")
    148. public R add(@RequestBody BozhuEntity bozhu, HttpServletRequest request){
    149. bozhu.setId(new Date().getTime()+new Double(Math.floor(Math.random()*1000)).longValue());
    150. //ValidatorUtils.validateEntity(bozhu);
    151. BozhuEntity user = bozhuService.selectOne(new EntityWrapper<BozhuEntity>().eq("bozhuzhanghao", bozhu.getBozhuzhanghao()));
    152. if(user!=null) {
    153. return R.error("用户已存在");
    154. }
    155. bozhu.setId(new Date().getTime());
    156. bozhuService.insert(bozhu);
    157. return R.ok();
    158. }
    159. /**
    160. * 修改
    161. */
    162. @RequestMapping("/update")
    163. public R update(@RequestBody BozhuEntity bozhu, HttpServletRequest request){
    164. //ValidatorUtils.validateEntity(bozhu);
    165. bozhuService.updateById(bozhu);//全部更新
    166. return R.ok();
    167. }
    168. /**
    169. * 删除
    170. */
    171. @RequestMapping("/delete")
    172. public R delete(@RequestBody Long[] ids){
    173. bozhuService.deleteBatchIds(Arrays.asList(ids));
    174. return R.ok();
    175. }
    176. /**
    177. * 提醒接口
    178. */
    179. @RequestMapping("/remind/{columnName}/{type}")
    180. public R remindCount(@PathVariable("columnName") String columnName, HttpServletRequest request,
    181. @PathVariable("type") String type,@RequestParam Map<String, Object> map) {
    182. map.put("column", columnName);
    183. map.put("type", type);
    184. if(type.equals("2")) {
    185. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    186. Calendar c = Calendar.getInstance();
    187. Date remindStartDate = null;
    188. Date remindEndDate = null;
    189. if(map.get("remindstart")!=null) {
    190. Integer remindStart = Integer.parseInt(map.get("remindstart").toString());
    191. c.setTime(new Date());
    192. c.add(Calendar.DAY_OF_MONTH,remindStart);
    193. remindStartDate = c.getTime();
    194. map.put("remindstart", sdf.format(remindStartDate));
    195. }
    196. if(map.get("remindend")!=null) {
    197. Integer remindEnd = Integer.parseInt(map.get("remindend").toString());
    198. c.setTime(new Date());
    199. c.add(Calendar.DAY_OF_MONTH,remindEnd);
    200. remindEndDate = c.getTime();
    201. map.put("remindend", sdf.format(remindEndDate));
    202. }
    203. }
    204. Wrapper<BozhuEntity> wrapper = new EntityWrapper<BozhuEntity>();
    205. if(map.get("remindstart")!=null) {
    206. wrapper.ge(columnName, map.get("remindstart"));
    207. }
    208. if(map.get("remindend")!=null) {
    209. wrapper.le(columnName, map.get("remindend"));
    210. }
    211. int count = bozhuService.selectCount(wrapper);
    212. return R.ok().put("count", count);
    213. }
    214. }

    文件上传功能 

    1. /**
    2. * 上传文件映射表
    3. */
    4. @RestController
    5. @RequestMapping("file")
    6. @SuppressWarnings({"unchecked","rawtypes"})
    7. public class FileController{
    8. @Autowired
    9. private ConfigService configService;
    10. /**
    11. * 上传文件
    12. */
    13. @RequestMapping("/upload")
    14. public R upload(@RequestParam("file") MultipartFile file, String type,HttpServletRequest request) throws Exception {
    15. if (file.isEmpty()) {
    16. throw new EIException("上传文件不能为空");
    17. }
    18. String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
    19. String fileName = new Date().getTime()+"."+fileExt;
    20. File dest = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName);
    21. file.transferTo(dest);
    22. if(StringUtils.isNotBlank(type) && type.equals("1")) {
    23. ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
    24. if(configEntity==null) {
    25. configEntity = new ConfigEntity();
    26. configEntity.setName("faceFile");
    27. configEntity.setValue(fileName);
    28. } else {
    29. configEntity.setValue(fileName);
    30. }
    31. configService.insertOrUpdate(configEntity);
    32. }
    33. return R.ok().put("file", fileName);
    34. }
    35. /**
    36. * 下载文件
    37. */
    38. @IgnoreAuth
    39. @RequestMapping("/download")
    40. public void download(@RequestParam String fileName, HttpServletRequest request, HttpServletResponse response) {
    41. try {
    42. File file = new File(request.getSession().getServletContext().getRealPath("/upload")+"/"+fileName);
    43. if (file.exists()) {
    44. response.reset();
    45. response.setHeader("Content-Disposition", "attachment; filename=\"" + fileName+"\"");
    46. response.setHeader("Cache-Control", "no-cache");
    47. response.setHeader("Access-Control-Allow-Credentials", "true");
    48. response.setContentType("application/octet-stream; charset=UTF-8");
    49. IOUtils.write(FileUtils.readFileToByteArray(file), response.getOutputStream());
    50. }
    51. } catch (IOException e) {
    52. e.printStackTrace();
    53. }
    54. }
    55. }

    登陆拦截功能实现 

    1. /**
    2. * 权限(Token)验证
    3. */
    4. @Component
    5. public class AuthorizationInterceptor implements HandlerInterceptor {
    6. public static final String LOGIN_TOKEN_KEY = "Token";
    7. @Autowired
    8. private TokenService tokenService;
    9. @Override
    10. public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    11. //支持跨域请求
    12. response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
    13. response.setHeader("Access-Control-Max-Age", "3600");
    14. response.setHeader("Access-Control-Allow-Credentials", "true");
    15. response.setHeader("Access-Control-Allow-Headers", "x-requested-with,request-source,Token, Origin,imgType, Content-Type, cache-control,postman-token,Cookie, Accept,authorization");
    16. response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));
    17. IgnoreAuth annotation;
    18. if (handler instanceof HandlerMethod) {
    19. annotation = ((HandlerMethod) handler).getMethodAnnotation(IgnoreAuth.class);
    20. } else {
    21. return true;
    22. }
    23. //从header中获取token
    24. String token = request.getHeader(LOGIN_TOKEN_KEY);
    25. /**
    26. * 不需要验证权限的方法直接放过
    27. */
    28. if(annotation!=null) {
    29. return true;
    30. }
    31. TokenEntity tokenEntity = null;
    32. if(StringUtils.isNotBlank(token)) {
    33. tokenEntity = tokenService.getTokenEntity(token);
    34. }
    35. if(tokenEntity != null) {
    36. request.getSession().setAttribute("userId", tokenEntity.getUserid());
    37. request.getSession().setAttribute("role", tokenEntity.getRole());
    38. request.getSession().setAttribute("tableName", tokenEntity.getTablename());
    39. request.getSession().setAttribute("username", tokenEntity.getUsername());
    40. return true;
    41. }
    42. PrintWriter writer = null;
    43. response.setCharacterEncoding("UTF-8");
    44. response.setContentType("application/json; charset=utf-8");
    45. try {
    46. writer = response.getWriter();
    47. writer.print(JSONObject.toJSONString(R.error(401, "请先登录")));
    48. } finally {
    49. if(writer != null){
    50. writer.close();
    51. }
    52. }
    53. // throw new EIException("请先登录", 401);
    54. return false;
    55. }
    56. }

  • 相关阅读:
    Vue+Leaflet.PM+Turf.js实现绘制多线段并自动生成辐射区(缓冲区)
    NetCore框架WTM的分表分库实现
    测试基础知识
    mybatis二级缓存机制及开启
    【Node.js】包与npm包
    【深度学习】常见开源框架介绍 || 主流深度学习框架 || Tensorflow || Pytorch
    从云计算到函数计算
    哈希表学习笔记
    bitmap基础介绍+holo实现离线UV计算
    C专家编程 第11章 你懂得C,所以C++不再话下 11.11 C++如何进行操作符重载
  • 原文地址:https://blog.csdn.net/m0_49113107/article/details/125010474