選課推薦交流平臺系統基於java ssm springboot實現

夏天到瞭、小雪來給大傢降降溫

話不多說、直接進入主題

主要功能模塊設計:

登錄註冊、首頁信息瀏覽、選課分類查看、選課詳情查看、評論交流、收藏、瀏覽量、以及後臺數據管理、用戶管理、選課類別管理、選課信息詳情管理、評論交流和回復管理、以及公告信息管理等

主要技術:

Java、springmvc、mybatis、mysql、tomcat、jquery、layui、JavaScript、html、css、jsp、log4j等一些常見的基本技術。

主要功能實現前端:

選課平臺首頁:

輸入http://localhost/訪問選課推薦交流平臺首頁、可以查看輪播圖以及各類信息、點擊進入詳情頁面

登錄註冊管理:

選課推薦分類:

點擊查看分類課程推薦信息、按照類別查看課程信息、管理員可以在後臺添加課程分類信息

以及根據訪問量來進行點擊排行、

課程詳情信息:

課程詳情可以查看課程詳情信息以及作者信息和瀏覽量等具體數據、也可以進行評論和收藏等操作

我的個人中心:

包括我的個人信息和收藏夾信息、

主要功能實現後臺:

系統主頁設計:

主要功能模塊有首頁的信息統計、選課類型管理、選課詳情管理、用戶管理、評論和公告管理等數據維護。

選課類型管理:

選課信息詳情管理:

列表信息查看添加修改刪除以及檢索等操作

詳情信息

通知公告信息:

數據列表查看和添加修改刪除等操作

用戶信息管理:

評論交流回復管理:

評論和回復的數據管理

部分關鍵代碼展示:

登錄模塊:

package com.longwang.controller;
 
import com.longwang.entity.Article;
import com.longwang.entity.Classify;
import com.longwang.entity.User;
import com.longwang.service.ArticleService;
import com.longwang.service.ClassifyService;
import com.longwang.service.NoticeService;
import com.longwang.service.UserService;
import com.longwang.util.DateUtil;
import com.longwang.util.StringUtil;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.*;
 
/**
 * 根路徑以及其他請求處理
 * 
 * @author 李楊勇
 *
 */
@Controller
public class IndexController {
 
  @Value("${imageFilePath}")
  private String imageFilePath; // 文件路徑
 
  @Resource
  private NoticeService noticeService;
 
  @Resource
  private UserService userService;
 
  @Resource
  private ArticleService articleService;
  @Resource
  private ClassifyService classifyService;
 
 
 
  @RequestMapping("/")
  public String index(HttpSession session) {
 
    // 查詢公告
    session.setAttribute("noticeList", noticeService.list(0, 5));
    return "index";// 跳轉到index.html
  }
 
 
  @RequestMapping("/delete")
  public Map<String, Object> delete(Integer userId) {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    userService.delete(userId);
    resultMap.put("errorNo", 0);
    return resultMap;
  }
  /**
   * 登錄頁面
   * 
   * @return
   */
  @RequestMapping("/login")
  public String login() {
    return "login";
  }
 
  /**
   * 前臺登錄頁面
   * 
   * @return
   */
  @RequestMapping("/webLogin")
  public String webLogin() {
    return "webLogin";
  }
 
  /**
   * 註冊
   * 
   * @return
   */
  @RequestMapping("/regist")
  public String regist() {
    return "regist";
  }
 
  /**
   * 保存註冊信息
   * 
   * @param user
   * @return
   */
  @RequestMapping("/saveUser")
  public String saveUser(User user) {
      List<Article> randomArticle = articleService.getRandomArticle(3);
      String ids="";
      for (int i = 0; i < randomArticle.size(); i++) {
          Integer articleId = randomArticle.get(i).getArticleId();
          ids+=articleId+",";
      }
      ids = ids.substring(0, ids.length() -1);
      user.setArticleIds(ids);
      userService.save(user);
 
    return "webLogin";
  }
 
  /**
   * 退出登錄
   * 
   * @param request
   * @return
   */
  @RequestMapping("/quit")
  public String quit(HttpServletRequest request) {
    HttpSession session = request.getSession();
    session.removeAttribute("user");
    return "index";
  }
 
 
  /**
   * 退出登錄
   * 
   * @param request
   * @return
   */
  @RequestMapping("/quitAdmin")
  public String quitAdmin(HttpServletRequest request) {
    HttpSession session = request.getSession();
    session.removeAttribute("user");
    return "login";
  }
 
  /**
   * 驗證登錄
   *
   * @param user
   * @param request
   * @return
   */
  @RequestMapping("/checkLogin")
  public ModelAndView checkLogin(User user, HttpServletRequest request) {
    ModelAndView mav = new ModelAndView();
    HttpSession session = request.getSession();
    User u = userService.findByUsernameAndPassword(user.getUsername(), user.getPassword());
    if (u == null) {
      mav.addObject("user", user);
      mav.addObject("errorInfo", "用戶名或者密碼錯誤!");
      mav.setViewName("webLogin");
    } else {
      u.setLatelyLoginTime(new Date());
      userService.save(u);
      session.setAttribute("user", u);
      mav.addObject("username", u.getUsername());
      mav.addObject("user", u);
      mav.addObject("success", true);
      mav.setViewName("/index");
    }
    return mav;
  }
 
  /**
   * 查看個人信息
   * 
   * @return
   */
  @RequestMapping("viewPerson")
  public ModelAndView viewPerson(HttpServletRequest request) {
    User user = (User) request.getSession().getAttribute("user");
    ModelAndView mav = new ModelAndView();
    User u = userService.findById(user.getUserId());
    mav.addObject("user", u);
    mav.setViewName("/viewPerson");
    return mav;
  }
 
  /**
   * 查看個人課程收藏夾
   * 
   * @return
   */
  @RequestMapping("viewCollection")
  public ModelAndView viewCollection(HttpServletRequest request, HttpSession session) {
    User user = (User) request.getSession().getAttribute("user");
    ModelAndView mav = new ModelAndView();
    User u = userService.findById(user.getUserId());
    String artIds = u.getArticleIds();
    List<String> result = new ArrayList<>();
    if (StringUtils.isNotBlank(artIds)) {
      result = Arrays.asList(StringUtils.split(artIds, ","));
    }
    List<Integer> retIds = new ArrayList<>();
    for (String temp : result) {
      retIds.add(Integer.valueOf(temp).intValue());
    }
    List<Article> retArt = articleService.findByListId(retIds);
    session.setAttribute("noticeList", noticeService.list(0, 5));
    mav.addObject("retArt", retArt);
    mav.addObject("user", u);
    mav.setViewName("/viewCollection");
    return mav;
  }
 
  /**
   * 查看個人關註用戶
   * 
   * @return
   */
  @RequestMapping("viewFocusUser")
  public ModelAndView viewFocusUser(HttpServletRequest request, HttpSession session) {
    User user = (User) request.getSession().getAttribute("user");
    ModelAndView mav = new ModelAndView();
    User u = userService.findById(user.getUserId());
    String userIds = u.getUserIds();
    List<String> result = new ArrayList<>();
    if (StringUtils.isNotBlank(userIds)) {
      result = Arrays.asList(StringUtils.split(userIds, ","));
    }
    List<Integer> retIds = new ArrayList<>();
    for (String temp : result) {
      retIds.add(Integer.valueOf(temp).intValue());
    }
    List<User> retArt = userService.findByListId(retIds);
    session.setAttribute("noticeList", noticeService.list(0, 5));
    mav.addObject("retArt", retArt);
    mav.addObject("user", u);
    mav.setViewName("/viewFocusUser");
    return mav;
  }
 
  /**
   * 保存用戶信息
   * 
   * @param user
   * @return
   */
  @RequestMapping("/save")
  public ModelAndView save(User user) {
    ModelAndView mav = new ModelAndView();
    userService.save(user);
    mav.setViewName("/index");
    return mav;
  }
 
  /**
   * 寫筆記頁面
   * 
   * @param request
   * @return
   */
  // @RequestMapping("notePage")
  // public String notePage(HttpServletRequest request, Model model) {
  // User user = (User) request.getSession().getAttribute("user");
  // if (user == null) {
  // return "webLogin";
  // }
  // List<Classify> list = classifyService.findAll();
  // model.addAttribute("list", list);
  // return "one";
  // }
 
  @RequestMapping("notePage")
  public ModelAndView notePage(HttpServletRequest request) {
    ModelAndView mav = new ModelAndView();
    User user = (User) request.getSession().getAttribute("user");
    if (user == null) {
      mav.setViewName("/webLogin");
      return mav;
    }
    List<Classify> list = classifyService.findAll();
    mav.addObject("list", list);
    mav.setViewName("/one");
    return mav;
  }
 
  /**
   * 保存筆記
   * 
   * @param article
   * @param request
   * @return
   */
  @RequestMapping("addNote")
  public ModelAndView addNote(Article article, HttpServletRequest request) {
    ModelAndView mav = new ModelAndView();
    // 獲取當前用戶信息
    User user = (User) request.getSession().getAttribute("user");
    article.setUserId(user.getUserId());
    article.setPublishDate(new Date());
    article.setClick(0);
    article.setCommentNum(0);
    article.setContentNoTag(StringUtil.Html2Text(article.getContent()));
    articleService.save(article);
    mav.setViewName("/index");
    return mav;
  }
 
  @RequestMapping("saveNote")
  public ModelAndView saveNote(Article article, HttpServletRequest request) {
    ModelAndView mav = new ModelAndView();
    Article a = articleService.findById(article.getArticleId());
    article.setPublishDate(a.getPublishDate());
    // 獲取當前用戶信息
    articleService.save(article);
    mav.setViewName("/index");
    return mav;
  }
 
  /**
   * 查看筆記
   * 
   * @return
   */
  @RequestMapping("viewNote")
  public String viewNote(HttpSession session) {
    session.setAttribute("noticeList", noticeService.list(0, 5));
    return "mylist";
  }
 
  @RequestMapping("/delete/{id}")
  public String delete(@PathVariable(value = "id") String id) throws Exception {
    articleService.delete(Integer.parseInt(id));
    return "mylist";
  }
 
  /**
   * 查看個人筆記加載數據列表
   * 
   * @param article
   * @param publishDates
   * @param page
   * @param pageSize
   * @return
   */
  @RequestMapping("/mylist")
  public Map<String, Object> list(Article article,
      @RequestParam(value = "publishDates", required = false) String publishDates,
      @RequestParam(value = "page", required = false) Integer page,
      @RequestParam(value = "pageSize", required = false) Integer pageSize, HttpServletRequest request) {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    // User user = (User) request.getSession().getAttribute("user");
    // article.setUserId(user.getUserId());
    String s_bPublishDate = null; // 開始時間
    String s_ePublishDate = null; // 結束時間
    if (StringUtil.isNotEmpty(publishDates)) {
      String[] strs = publishDates.split(" - "); // 拆分時間段
      s_bPublishDate = strs[0];
      s_ePublishDate = strs[1];
    }
    Long total = articleService.getCount(article, s_bPublishDate, s_ePublishDate);
    int totalPage = (int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1); // 總頁數
    resultMap.put("totalPage", totalPage);
    resultMap.put("errorNo", 0);
    resultMap.put("data", articleService.list(article, s_bPublishDate, s_ePublishDate, page - 1, pageSize));
    resultMap.put("total", total);
    return resultMap;
  }
 
  /**
   * 後臺默認首頁
   * 
   * @return
   */
  @RequestMapping("/index")
  public String root() {
    return "/common/index";
  }
 
  /**
   * 博主信息頁面
   * 
   * @return
   */
  @RequestMapping("/blogger")
  public String blogger() {
    return "/blogger/index";
  }
 
  /**
   * 圖片上傳處理 @Title: ckeditorUpload @param file 圖片文件 @return 參數說明 @return
   * Map<String,Object> 返回類型 @throws
   */
  @ResponseBody
  @RequestMapping("/upload")
  public Map<String, Object> ckeditorUpload(@RequestParam("file") MultipartFile file) {
    Map<String, Object> resultMap = new HashMap<String, Object>();
    Map<String, Object> resultMap1 = new HashMap<String, Object>();
    String fileName = file.getOriginalFilename(); // 獲取文件名
    String suffixName = fileName.substring(fileName.lastIndexOf(".")); // 獲取文件的後綴
    String newFileName = "";
    try {
      newFileName = DateUtil.getCurrentDateStr() + suffixName; // 新文件名
      FileUtils.copyInputStreamToFile(file.getInputStream(), new File(imageFilePath + newFileName)); // 上傳
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    resultMap.put("code", 0);
    resultMap1.put("filePath", newFileName);
    resultMap.put("data", resultMap1);
    return resultMap;
  }
 
}

配置模塊:

server: 
  port: 80
  servlet:
    context-path: /
  
spring: 
  datasource: 
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/choosing_courses?useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai
    username: root
    password: 123456
  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    database-platform: org.hibernate.dialect.MySQLDialect
  thymeleaf:
    cache: false
 
thymeleaf:
    prefix: classpath:/templates/
 
MD5Salt: longwang
 
 
imageFilePath: C:\\Users\\Administrator\\Desktop\\choosingCourses\\src\\main\\webapp\\static\\images\\
downloadImagePath:  C:\\Users\\Administrator\\Desktop\\choosingCourses\\src\\main\\webapp
lucenePath: C:\\Users\\Administrator\\Desktop\\choosingCourses\\lucene
 
 

主要表設計:

用戶表:

CREATE TABLE `NewTable` (
`user_id`  int(11) NOT NULL AUTO_INCREMENT ,
`head_portrait`  varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`lately_login_time`  datetime NULL DEFAULT NULL ,
`nickname`  varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`registration_date`  datetime NULL DEFAULT NULL ,
`sex`  varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`open_id`  varchar(200) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`password`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`username`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`article_ids`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`birthday`  date NULL DEFAULT NULL ,
`momo`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`phone`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
`user_ids`  varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL ,
PRIMARY KEY (`user_id`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8 COLLATE=utf8_general_ci
AUTO_INCREMENT=20
ROW_FORMAT=COMPACT
;
 

選課類型表:

CREATE TABLE `NewTable` (
`classify_id`  int(11) NOT NULL AUTO_INCREMENT ,
`classify_name`  varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
PRIMARY KEY (`classify_id`)
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci
AUTO_INCREMENT=27
ROW_FORMAT=COMPACT
;
 

選課詳情表:

CREATE TABLE `NewTable` (
`article_id`  int(11) NOT NULL AUTO_INCREMENT ,
`author`  varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
`click`  int(11) NULL DEFAULT NULL ,
`comment_num`  int(11) NULL DEFAULT NULL ,
`content`  text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL ,
`image_name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ,
`is_original`  int(11) NULL DEFAULT NULL ,
`is_top`  int(11) NULL DEFAULT NULL ,
`publish_date`  datetime NULL DEFAULT NULL ,
`title`  varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL ,
`classify_id`  int(11) NULL DEFAULT NULL ,
`user_id`  int(11) NULL DEFAULT NULL ,
PRIMARY KEY (`article_id`),
FOREIGN KEY (`classify_id`) REFERENCES `t_classify` (`classify_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `FKo4fros4yfq1m9ay7sgtlcvbc4` (`classify_id`) USING BTREE 
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci
AUTO_INCREMENT=58
ROW_FORMAT=COMPACT
;
 

評論交流表:

CREATE TABLE `NewTable` (
`comment_id`  int(11) NOT NULL AUTO_INCREMENT ,
`comment_date`  datetime NULL DEFAULT NULL ,
`content`  varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ,
`article_id`  int(11) NULL DEFAULT NULL ,
`user_id`  int(11) NULL DEFAULT NULL ,
PRIMARY KEY (`comment_id`),
FOREIGN KEY (`article_id`) REFERENCES `t_article` (`article_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
FOREIGN KEY (`user_id`) REFERENCES `t_user` (`user_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `FKlsvvc2ob8lxg2m9qqry15ru0y` (`article_id`) USING BTREE ,
INDEX `FKtamaoacctq4qpko6bvtv0ke1p` (`user_id`) USING BTREE 
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci
AUTO_INCREMENT=15
ROW_FORMAT=COMPACT
;
 

回復信息表:

CREATE TABLE `NewTable` (
`reply_id`  int(11) NOT NULL AUTO_INCREMENT ,
`content`  varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL ,
`reply_date`  datetime NULL DEFAULT NULL ,
`comment_id`  int(11) NULL DEFAULT NULL ,
`user_id`  int(11) NULL DEFAULT NULL ,
PRIMARY KEY (`reply_id`),
FOREIGN KEY (`comment_id`) REFERENCES `t_comment` (`comment_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
FOREIGN KEY (`user_id`) REFERENCES `t_user` (`user_id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
INDEX `FKk4ydp71wampdbnguly8iks4rf` (`comment_id`) USING BTREE ,
INDEX `FKslt6r79iw1p9cbxns09erjv6v` (`user_id`) USING BTREE 
)
ENGINE=InnoDB
DEFAULT CHARACTER SET=utf8mb4 COLLATE=utf8mb4_general_ci
AUTO_INCREMENT=6
ROW_FORMAT=COMPACT
;
 

到此這篇關於選課推薦交流平臺系統基於java ssm springboot實現的文章就介紹到這瞭,更多相關交流平臺系統內容請搜索WalkonNet以前的文章或繼續瀏覽下面的相關文章希望大傢以後多多支持WalkonNet!

推薦閱讀: