基于javaweb的美食菜谱分享平台系统设计和实现(java+springboot+mysql+ssm)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+springboot的美食菜谱分享平台系统设计和实现(java+springboot+mysql+ssm)
主要技术实现:spring、 springmvc、 springboot、mybatis 、session、 jquery 、 md5 、bootstarp.js tomcat、拦截器等。
具体主要功能模块如下:
1.用户模块管理:用户登录、用户注册、用户的查询、添加、删除操作、 2.美食分享笔记管理:分享笔记列表的展示、添加、修改、删除操作、 3.美食笔记详情管理:美食笔记详情列表的查看、添加、删除等操作、 4.管理员信息管理:管理员信息的查看、修改、 5.公告信息管理:公告信息的查看、添加、修改、删除操作、 6.用户模块管理:用户列表查询、添加、删除、 7.用户评论模块管理:用户评论查询、添加、删除、 8.注销退出登录管理
给大家截一部分效果图吧 系统首页主要功能:
分类查看没事菜谱信息以及智能推荐:
美食分享笔记详情信息查看、用户登录后可以进行评论、浏览量会增加、用户可以收藏当前文档信息、可以点击查看作者信息、可以对作者进行关注等操作:
用户评论操作:
富文本编辑器添加美食分享笔记:
个人中心我的收藏 我的关注等:
关注用户信息以及具体功能操作等:
后台管理主要功能:用户管理、美食菜谱笔记管理、美食菜谱详情发布以及评论等管理
代码结构:
项目文档报告:
时光轴控制器:
/**
- 时光轴控制器
*/
@RestController
@RequestMapping(“/timeline”)
public class TimelineController {
@Resource
private TimelineService timelineService;
/**
-
查询时光轴
-
@param page
-
@param pageSize
-
@return
*/
@RequestMapping(“/list”)
public Map<String, Object> list2() {
Map<String, Object> resultMap = new HashMap<>();
List maps = timelineService.list(null, 0, 100);
if (CollectionUtils.isNotEmpty(maps)) {
Map<String, Object> jsonMap = new LinkedHashMap<String, Object>();
for (Timeline map : maps) {
Map<String, Object> yearMap = (Map<String, Object>) jsonMap.get(map.getYear());
if (null == yearMap) {
yearMap = new LinkedHashMap<String, Object>();
yearMap.put(“year”, map.getYear());
Map<String, Object> monthMap = (Map<String, Object>) yearMap.get(“month”);
if (null == monthMap) {
monthMap = new LinkedHashMap<String, Object>();
List<Map<String, Object>> monthList = (List<Map<String, Object>>) monthMap.get(map.getMonth());
if (null == monthList) {
monthList = new ArrayList<>();
monthMap.remove(map.getMonth());
Map<String, Object> obj = new HashMap<>();
obj.put(“create_time”, DateUtil.formatDate(map.getPublishDate(), “MM月dd日 hh:mm”));
obj.put(“content”, map.getContent());
monthList.add(obj);
monthMap.put(map.getMonth(), monthList);
yearMap.remove(“month”);
yearMap.put(“month”, monthMap);
jsonMap.remove(map.getYear());
jsonMap.put(map.getYear(), yearMap);
List<Map<String, Object>> datas = new ArrayList<Map<String, Object>>();
for (Map.Entry<String, Object> entry : jsonMap.entrySet()) {
datas.add((Map<String, Object>) entry.getValue());
resultMap.put(“datas”, datas);
resultMap.put(“result”, 1);
}else {
resultMap.put(“data”, “还没有时光轴数据!”);
return resultMap;
根路径以及其他请求处理:
/**
- 根路径以及其他请求处理
*/
@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
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 result = new ArrayList<>();
if (StringUtils.isNotBlank(artIds)) {
result = Arrays.asList(StringUtils.split(artIds, “,”));
List retIds = new ArrayList<>();
for (String temp : result) {
retIds.add(Integer.valueOf(temp).intValue());
List
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 result = new ArrayList<>();
if (StringUtils.isNotBlank(userIds)) {
result = Arrays.asList(StringUtils.split(userIds, “,”));
List retIds = new ArrayList<>();
for (String temp : result) {
retIds.add(Integer.valueOf(temp).intValue());
List 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 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 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;
评论控制器:
/**
- 评论控制器
*/
@RestController
@RequestMapping(“/comment”)
public class CommentController {
@Resource
private CommentService commentService;
@Resource
private ArticleService articleService;
@Resource
private ReplyService replyService;
/**
-
分页查询评论
-
@param comment
-
@param page
-
@param pageSize
-
@return
*/
@RequestMapping(“/list”)
public Map<String, Object> commentList(Comment comment, @RequestParam(value = “page”, required = false) Integer page,
@RequestParam(value = “pageSize”, required = false) Integer pageSize) {
List commentList = commentService.list(comment, null, null, page - 1, pageSize, null);
Long total = commentService.getCount(comment, null, null, null);
int totalPage = (int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put(“totalPage”, totalPage);
resultMap.put(“data”, commentList);
return resultMap;
/**
-
分页查询评论
-
@param page
-
@param pageSize
-
@return
*/
@RequestMapping(“/massageList”)
public Map<String, Object> massageList(@RequestParam(value = “page”, required = false) Integer page,
@RequestParam(value = “pageSize”, required = false) Integer pageSize) {
List commentList = commentService.massageList(page - 1, pageSize);
Long total = commentService.getCount2();
int totalPage = (int) (total % pageSize == 0 ? total / pageSize : total / pageSize + 1);
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put(“totalPage”, totalPage);
resultMap.put(“data”, commentList);
return resultMap;
/**
-
添加评论
-
@Title: add
-
@param comment 评论实体
-
@return 参数说明
-
@return Map<String,Object> 返回类型
-
@throws
*/
@RequestMapping(“/add”)
public Map<String, Object> add(Comment comment, HttpSession session) {
User currentUser = (User) session.getAttribute(“user”);
Map<String, Object> resultMap = new HashMap<String, Object>();
comment.setCommentDate(new Date());
comment.setUser(currentUser);
commentService.add(comment);
if (comment.getArticle() != null) {
articleService.increaseComment(comment.getArticle().getArticleId());
resultMap.put(“comment”, comment);
resultMap.put(“success”, true);
return resultMap;