• 基于Spring Boot+Vue的论坛网站


    末尾获取源码
    作者介绍:大家好,我是墨韵,本人4年开发经验,专注定制项目开发

    更多项目:CSDN主页YAML墨韵

    学如逆水行舟,不进则退。学习如赶路,不能慢一步。

    目录

    一、项目简介

    二、开发技术与环境配置

    2.1 SpringBoot框架

    2.2 Java语言简介

    2.3 Vue的介绍

    2.4 mysql数据库介绍

    2.5 B/S架构

    三、系统功能实现

    四、系统项目截图

    用户模块的实现

    交流论坛

    交流论坛评论

    管理员模块的实现 

    登录界面图

    用户信息管理

    普通管理员管理

    五、核心代码

    5.1、文件上传

    5.2、数据库配置

    5.3、登录功能实现

    5.4、业务层(Service)

    5.5、数据访问层(Dao)


    一、项目简介

    随着信息技术在管理上越来越深入而广泛的应用,管理信息系统的实施在技术上已逐步成熟。本文介绍了论坛网站的开发全过程。通过分析论坛网站管理的不足,创建了一个计算机管理论坛网站的方案。文章介绍了论坛网站的系统分析部分,包括可行性分析等,系统设计部分主要介绍了系统功能设计和数据库设计。

    本论文系统地描绘了整个网上论坛管理系统的设计与实现,主要实现的功能有以下几点:管理员;首页、个人中心、用户管理、公告管理、公告类型管理、热门帖子管理、帖子分类管理、留言板管理、论坛新天地、我的收藏管理、系统管理,前台首页;首页、公告、热门帖子、论坛新天地、新闻资讯、留言反馈、个人中心、后台管理、客服中心,用户;首页、个人中心等功能,其具有简单的接口,方便的应用,强大的互动,完全基于互联网的特点。

    二、开发技术与环境配置

    以Java语言为开发工具,利用了当前先进的springboot框架,以IDEA为系统开发工具,MySQL为后台数据库,vue为后台管理页面开发的一个论坛网站系统。

    2.1 SpringBoot框架

    SpringBoot是一个全新开源的轻量级框架。基于Spring4.0设计,其不仅继承了Spring框架原来有的优秀特性,而且还通过简化配置文件来进一步简化了Spring应用的整个搭建以及开发过程。另外在原本的Spring中由于随着项目的扩大导入的jar包数量越来越大,随之出现了jar包版本之间的兼容性问题,而此时SpringBoot通过集成大量的框架使得依赖包的版本冲突,以及引用的不稳定性问题得到了很好的解决。

    SpringBoot可以看做是Spring的加强版本,但实质上都是Spring的相关技术,有了这些优秀的开源框架,程序员在开发过程中将事半功倍。

    2.2 Java语言简介

    Java是由SUN公司推出,该公司于2010年被oracle公司收购。Java本是印度尼西亚的一个叫做爪洼岛的英文名称,也因此得来java是一杯正冒着热气咖啡的标识。Java语言在移动互联网的大背景下具备了显著的优势和广阔的前景,它是面向对象的,分布式的,动态的,具有平台无关性、安全性、健壮性。Java语言的基本语句语法和C++一样,但是它面向对象的技术更加彻底,因为Java要求将所有的内容都必须封装成类,把类作为程序的基本单位。由于不允许类外有变量、方法。 Java语言的分布式体现在数据分布和操作分布,它是面向网络的语言,可以处理TCP/IP协议,它也支持客户机/服务器的计算模式。Java语言的动态性是指类在运行时是动态安装的,使得Java可以动态的维护程序。Java不支持指针,对内存访问的所有操作都是通过对象实例化实现的,这样就避免了指针操作中易产生的错误,同时也预防了病毒对系统的破坏和威胁。

    Java语言的编程风格与C语言非常接近,它继承了C++面向对象技术的核心,它面世之后发展迅速,非常流行,对高级C语言形成了很大的冲击。业内人士称之为“一次编译、到处执行”。当然java也有缺点,在每次执行编译后,字节码都需要消耗一定的时间,在某些程度上降低了性能。但是这并不影响java成为此次设计语言的选择。Java语言简单易学,使用它的编程时间短,功能性强,开发者学习起来更简便、更快。Java的主要特性有以下几个:

    面向对象
    面向对象有四个特点:封装、继承、多态、抽象。抽象是指忽略一个问题中的次要部分,关注主要部分。多态是指对同一种消息做出的不同反应。继承是指在原有的父类方法基础上增加自己独有的方法,而不改变原来父类。

    平台无关性、
    Java编译出来的是字节码,直接由虚拟机执行。在任何平台上,只要有Java虚拟机,Java代码都能运行。

    可靠性和安全性
    Java对内存的访问都必须通过对象的实例变量来实现,避免了指针中出现的错误。

    多线程
    Java提供了多线程功能,利用编程实现同一时间同时工作的功能。

    2.3 Vue的介绍

    Vue.js致力于构建数据驱动的web应用开发框架,以简洁化,轻量级,数据驱动,模块友好等优势深受企业以及前端开发者的喜爱,成为前端开发人员必备的技能。Vue3.0的出现,又带动周边生态的发展,奠定了vue在企业级开发的重要地位。

    Vue是一套用于构建用户界面的渐进式框架。与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用。Vue 的核心库只关注视图层,不仅易于上手,还便于与第三方库或既有项目整合。另一方面,当与现代化的工具链以及各种支持类库结合使用时,Vue 也完全能够为复杂的单页应用提供驱动。

    渐进式框架做分层设计,每层都可选,不同层可以灵活接入其他方案。而当你都想用官方的实现时,会发现也早已准备好,各层之间包括配套工具都能比接入其他方案更便捷地协同工作。 一个个放入,放多少就做多少。

    2.4 mysql数据库介绍

    利用MYSQL的数据独立性、安全性等特点,在软件项目中对数据进行操作,可以保证数据准确无误,并降低了程序员的应用开发时间。
    MYSQL的特点是支持多线程,能方便的对系统资源充分利用,有效提高速度,还提供多种方式途径来对数据库进行连接;MYSQL的功能相对弱小、规模也小,但本系统要求不高,MYSQL完全可以满足本系统使用。
    利用MYSQL建立系统数据库,不仅有利于数据处理业务的早期整合,还能利于发展后两种数据扩展的操作。

    2.5 B/S架构

    B/S结构是目前使用最多的结构模式,它可以使得系统的开发更加的简单,好操作,而且还可以对其进行维护。使用该结构时只需要在计算机中安装数据库,和一些很常用的浏览器就可以了。浏览器就会与数据库进行信息的连接,可以实现很多的功能,B/S结构是可以直接进行使用的,而且B/S结构在使用中极大的减少了工作的维护。基于B/S的软件,所有的数据库之间都是相互独立的,因此是非常安全的。因为基于B/S结构可以清楚的看到系统正在处理的业务,并且能够及时的让管理人员做出决策,这样就可以避免企业的损失。B/S结构的基本特点是集中式的管理模式,用户使用系统生成数据后,这些数据就可以存储到系统的数据库中,方便日后能够用到,这样就可以满足人们的所有的需求。

    三、系统功能实现

    四、系统项目截图

    用户模块的实现

    交流论坛

    用户登录可以发布交流论坛

    交流论坛评论

    用户登录后可以对其他用户发布的论坛信息进行评论操作

    管理员模块的实现 

    登录界面图

    用户信息管理

    论坛网站的系统管理员可以管理用户,可以对用户信息添加修改删除以及查询操作。具体界面的展示

    普通管理员管理

    系统管理员可以查看对普通管理员信息进行添加,修改,删除以及查询操作

    五、核心代码

    5.1、文件上传

    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) throws Exception {
    15. if (file.isEmpty()) {
    16. throw new EIException("上传文件不能为空");
    17. }
    18. String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
    19. File path = new File(ResourceUtils.getURL("classpath:static").getPath());
    20. if(!path.exists()) {
    21. path = new File("");
    22. }
    23. File upload = new File(path.getAbsolutePath(),"/upload/");
    24. if(!upload.exists()) {
    25. upload.mkdirs();
    26. }
    27. String fileName = new Date().getTime()+"."+fileExt;
    28. File dest = new File(upload.getAbsolutePath()+"/"+fileName);
    29. file.transferTo(dest);
    30. /**
    31. * 如果使用idea或者eclipse重启项目,发现之前上传的图片或者文件丢失,将下面一行代码注释打开
    32. * 请将以下的"D:\\springbootq33sd\\src\\main\\resources\\static\\upload"替换成你本地项目的upload路径,
    33. * 并且项目路径不能存在中文、空格等特殊字符
    34. */
    35. // FileUtils.copyFile(dest, new File("D:\\springbootq33sd\\src\\main\\resources\\static\\upload"+"/"+fileName)); /**修改了路径以后请将该行最前面的//注释去掉**/
    36. if(StringUtils.isNotBlank(type) && type.equals("1")) {
    37. ConfigEntity configEntity = configService.selectOne(new EntityWrapper().eq("name", "faceFile"));
    38. if(configEntity==null) {
    39. configEntity = new ConfigEntity();
    40. configEntity.setName("faceFile");
    41. configEntity.setValue(fileName);
    42. } else {
    43. configEntity.setValue(fileName);
    44. }
    45. configService.insertOrUpdate(configEntity);
    46. }
    47. return R.ok().put("file", fileName);
    48. }
    49. /**
    50. * 下载文件
    51. */
    52. @IgnoreAuth
    53. @RequestMapping("/download")
    54. public ResponseEntity<byte[]> download(@RequestParam String fileName) {
    55. try {
    56. File path = new File(ResourceUtils.getURL("classpath:static").getPath());
    57. if(!path.exists()) {
    58. path = new File("");
    59. }
    60. File upload = new File(path.getAbsolutePath(),"/upload/");
    61. if(!upload.exists()) {
    62. upload.mkdirs();
    63. }
    64. File file = new File(upload.getAbsolutePath()+"/"+fileName);
    65. if(file.exists()){
    66. HttpHeaders headers = new HttpHeaders();
    67. headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
    68. headers.setContentDispositionFormData("attachment", fileName);
    69. return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
    70. }
    71. } catch (IOException e) {
    72. e.printStackTrace();
    73. }
    74. return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
    75. }
    76. }

    5.2、数据库配置

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

    5.3、登录功能实现

    1. package com.controller;
    2. import java.util.Arrays;
    3. import java.util.Calendar;
    4. import java.util.Date;
    5. import java.util.Map;
    6. import javax.servlet.http.HttpServletRequest;
    7. import org.springframework.beans.factory.annotation.Autowired;
    8. import org.springframework.stereotype.Controller;
    9. import org.springframework.web.bind.annotation.GetMapping;
    10. import org.springframework.web.bind.annotation.PathVariable;
    11. import org.springframework.web.bind.annotation.PostMapping;
    12. import org.springframework.web.bind.annotation.RequestBody;
    13. import org.springframework.web.bind.annotation.RequestMapping;
    14. import org.springframework.web.bind.annotation.RequestParam;
    15. import org.springframework.web.bind.annotation.ResponseBody;
    16. import org.springframework.web.bind.annotation.RestController;
    17. import com.annotation.IgnoreAuth;
    18. import com.baomidou.mybatisplus.mapper.EntityWrapper;
    19. import com.entity.TokenEntity;
    20. import com.entity.UserEntity;
    21. import com.service.TokenService;
    22. import com.service.UserService;
    23. import com.utils.CommonUtil;
    24. import com.utils.MPUtil;
    25. import com.utils.PageUtils;
    26. import com.utils.R;
    27. import com.utils.ValidatorUtils;
    28. /**
    29. * 登录相关
    30. */
    31. @RequestMapping("users")
    32. @RestController
    33. public class UserController{
    34. @Autowired
    35. private UserService userService;
    36. @Autowired
    37. private TokenService tokenService;
    38. /**
    39. * 登录
    40. */
    41. @IgnoreAuth
    42. @PostMapping(value = "/login")
    43. public R login(String username, String password, String captcha, HttpServletRequest request) {
    44. UserEntity user = userService.selectOne(new EntityWrapper().eq("username", username));
    45. if(user==null || !user.getPassword().equals(password)) {
    46. return R.error("账号或密码不正确");
    47. }
    48. String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
    49. return R.ok().put("token", token);
    50. }
    51. /**
    52. * 注册
    53. */
    54. @IgnoreAuth
    55. @PostMapping(value = "/register")
    56. public R register(@RequestBody UserEntity user){
    57. if(userService.selectOne(new EntityWrapper().eq("username",
    58. user.getUsername())) !=null) {
    59. return R.error("用户已存在");
    60. }
    61. userService.insert(user);
    62. return R.ok();
    63. }
    64. /**
    65. * 退出
    66. */
    67. @GetMapping(value = "logout")
    68. public R logout(HttpServletRequest request) {
    69. request.getSession().invalidate();
    70. return R.ok("退出成功");
    71. }
    72. /**
    73. * 密码重置
    74. */
    75. @IgnoreAuth
    76. @RequestMapping(value = "/resetPass")
    77. public R resetPass(String username, HttpServletRequest request){
    78. UserEntity user = userService.selectOne(new EntityWrapper
    79. ().eq("username", username));
    80. if(user==null) {
    81. return R.error("账号不存在");
    82. }
    83. user.setPassword("123456");
    84. userService.update(user,null);
    85. return R.ok("密码已重置为:123456");
    86. }
    87. /**
    88. * 列表
    89. */
    90. @RequestMapping("/page")
    91. public R page(@RequestParam Map params,UserEntity user){
    92. EntityWrapper ew = new EntityWrapper();
    93. PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
    94. return R.ok().put("data", page);
    95. }
    96. /**
    97. * 列表
    98. */
    99. @RequestMapping("/list")
    100. public R list( UserEntity user){
    101. EntityWrapper ew = new EntityWrapper();
    102. ew.allEq(MPUtil.allEQMapPre( user, "user"));
    103. return R.ok().put("data", userService.selectListView(ew));
    104. }
    105. /**
    106. * 信息
    107. */
    108. @RequestMapping("/info/{id}")
    109. public R info(@PathVariable("id") String id){
    110. UserEntity user = userService.selectById(id);
    111. return R.ok().put("data", user);
    112. }
    113. /**
    114. * 获取用户的session用户信息
    115. */
    116. @RequestMapping("/session")
    117. public R getCurrUser(HttpServletRequest request){
    118. Long id = (Long)request.getSession().getAttribute("userId");
    119. UserEntity user = userService.selectById(id);
    120. return R.ok().put("data", user);
    121. }
    122. /**
    123. * 保存
    124. */
    125. @PostMapping("/save")
    126. public R save(@RequestBody UserEntity user){
    127. if(userService.selectOne(new EntityWrapper().eq("username",
    128. user.getUsername())) !=null) {
    129. return R.error("用户已存在");
    130. }
    131. userService.insert(user);
    132. return R.ok();
    133. }
    134. /**
    135. * 修改
    136. */
    137. @RequestMapping("/update")
    138. public R update(@RequestBody UserEntity user){
    139. userService.updateById(user);//全部更新
    140. return R.ok();
    141. }
    142. /**
    143. * 删除
    144. */
    145. @RequestMapping("/delete")
    146. public R delete(@RequestBody Long[] ids){
    147. userService.deleteBatchIds(Arrays.asList(ids));
    148. return R.ok();
    149. }
    150. }

    5.4、业务层(Service)

    1. package com.service;
    2. import java.util.List;
    3. import java.util.Map;
    4. import org.apache.ibatis.annotations.Param;
    5. import com.baomidou.mybatisplus.mapper.Wrapper;
    6. import com.baomidou.mybatisplus.service.IService;
    7. import com.entity.UserEntity;
    8. import com.utils.PageUtils;
    9. /**
    10. * 系统用户
    11. */
    12. public interface UserService extends IService {
    13. PageUtils queryPage(Map params);
    14. List selectListView(Wrapper wrapper);
    15. PageUtils queryPage(Map params,Wrapper wrapper);
    16. }

    5.5、数据访问层(Dao)

    1. package com.dao;
    2. import java.util.List;
    3. import org.apache.ibatis.annotations.Param;
    4. import com.baomidou.mybatisplus.mapper.BaseMapper;
    5. import com.baomidou.mybatisplus.mapper.Wrapper;
    6. import com.baomidou.mybatisplus.plugins.pagination.Pagination;
    7. import com.entity.UserEntity;
    8. /**
    9. * 用户
    10. */
    11. public interface UserDao extends BaseMapper {
    12. List selectListView(@Param("ew") Wrapper wrapper);
    13. List selectListView(Pagination page,@Param("ew") Wrapper wrapper);
    14. }

  • 相关阅读:
    数据结构——排序算法(冒泡排序、选择排序、插入排序、归并排序、快速排序、搜索算法)
    分类、回归算法简单介绍
    [s905l3]性价比神机mgv3000全网首拆,刷armbian实现更多价值!
    2-1线性表-顺序表
    【VBA】获取指定目录下的Excel文件,并合并所有excel中的内容。
    资源共享共赢系统应用
    『heqingchun-ubuntu系统下安装cuda与cudnn』
    交叉编译glib
    Python数据分析与机器学习38-Xgboost算法
    FFplay文档解读-38-视频过滤器十三
  • 原文地址:https://blog.csdn.net/Yaml4/article/details/136435816