从不会做饭到系统开发高手:食谱健康管理系统让SpringBoot初学者逆袭成功

38 阅读4分钟

一、个人简介

  • 💖💖作者:计算机编程果茶熊
  • 💙💙个人简介:曾长期从事计算机专业培训教学,担任过编程老师,同时本人也热爱上课教学,擅长Java、微信小程序、Python、Golang、安卓Android等多个IT方向。会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。平常喜欢分享一些自己开发中遇到的问题的解决办法,也喜欢交流技术,大家有技术代码这一块的问题可以问我!
  • 💛💛想说的话:感谢大家的关注与支持!
  • 💜💜
  • 网站实战项目
  • 安卓/小程序实战项目
  • 💕💕文末获取源码联系计算机编程果茶熊

二、系统介绍

  • 开发语言:Java+Python
  • 数据库:MySQL
  • 系统架构:B/S
  • 后端框架:SpringBoot(Spring+SpringMVC+Mybatis)+Django
  • 前端:Vue+HTML+CSS+JavaScript+jQuery
  • 基于SpringBoot的食谱健康管理系统是一款基于B/S架构的综合性健康饮食管理平台,采用Java+SpringBoot作为后端核心框架。
  • 结合Spring+SpringMVC+Mybatis技术栈构建稳定的服务层,前端运用Vue+ElementUI+HTML技术实现美观易用的用户界面,数据存储采用MySQL关系型数据库确保数据的完整性和安全性。系统功能涵盖八大核心模块:首页提供系统概览和快捷入口,个人中心支持用户信息管理和个性化设置,用户管理模块实现用户注册登录和权限控制,食谱分类管理帮助用户按菜系、口味、营养需求等维度组织食谱内容,食谱信息管理提供详细的菜品制作步骤、营养成分和烹饪技巧,周食谱健康安排管理功能让用户可以制定科学的一周饮食计划并跟踪营养摄入情况,材料信息管理模块详细记录各类食材的营养价值、保存方法和采购信息,美食论坛则为用户提供交流烹饪心得和分享健康饮食经验的社区平台。整个系统通过现代化的前后端分离架构设计,不仅保证了系统的高可用性和良好的用户体验,还为用户提供了从食谱搜索、营养分析到健康规划的一站式饮食管理解决方案,特别适合注重健康生活方式的现代用户群体使用。

三、基于SpringBoot的食谱健康管理系统-视频解说

从不会做饭到系统开发高手:食谱健康管理系统让SpringBoot初学者逆袭成功

四、基于SpringBoot的食谱健康管理系统-功能展示

个人中心.png

公告信息.png

后台健康食谱管理.png

食谱推荐.png

食谱详情.png

首页.png

营养食谱详情.png

五、基于SpringBoot的食谱健康管理系统-代码展示

// 食谱信息管理核心业务处理
@PostMapping("/addRecipe")
public ResponseEntity<String> addRecipe(@RequestBody Recipe recipe) {
    if (recipe.getRecipeName() == null || recipe.getRecipeName().trim().isEmpty()) {
        return ResponseEntity.badRequest().body("食谱名称不能为空");
    }
    if (recipe.getCategoryId() == null) {
        return ResponseEntity.badRequest().body("食谱分类不能为空");
    }
    
    Recipe existingRecipe = recipeMapper.findByName(recipe.getRecipeName());
    if (existingRecipe != null) {
        return ResponseEntity.badRequest().body("食谱名称已存在");
    }
    
    recipe.setCreateTime(new Date());
    recipe.setStatus(1);
    
    List<String> ingredients = recipe.getIngredientsList();
    double totalCalories = 0.0;
    double totalProtein = 0.0;
    double totalFat = 0.0;
    double totalCarbohydrate = 0.0;
    
    for (String ingredient : ingredients) {
        Material material = materialMapper.findByName(ingredient);
        if (material != null) {
            totalCalories += material.getCalories();
            totalProtein += material.getProtein();
            totalFat += material.getFat();
            totalCarbohydrate += material.getCarbohydrate();
        }
    }
    
    recipe.setTotalCalories(totalCalories);
    recipe.setTotalProtein(totalProtein);
    recipe.setTotalFat(totalFat);
    recipe.setTotalCarbohydrate(totalCarbohydrate);
    
    int result = recipeMapper.insert(recipe);
    if (result > 0) {
        return ResponseEntity.ok("食谱添加成功");
    } else {
        return ResponseEntity.status(500).body("食谱添加失败");
    }
}

// 周食谱健康安排管理核心业务处理
@PostMapping("/createWeeklyPlan")
public ResponseEntity<Map<String, Object>> createWeeklyPlan(@RequestBody WeeklyPlan weeklyPlan) {
    Map<String, Object> response = new HashMap<>();
    
    if (weeklyPlan.getUserId() == null) {
        response.put("success", false);
        response.put("message", "用户ID不能为空");
        return ResponseEntity.badRequest().body(response);
    }
    
    Date startDate = weeklyPlan.getStartDate();
    Date endDate = new Date(startDate.getTime() + 6 * 24 * 60 * 60 * 1000);
    weeklyPlan.setEndDate(endDate);
    
    WeeklyPlan existingPlan = weeklyPlanMapper.findByUserIdAndDateRange(weeklyPlan.getUserId(), startDate, endDate);
    if (existingPlan != null) {
        response.put("success", false);
        response.put("message", "该时间段已存在周食谱安排");
        return ResponseEntity.badRequest().body(response);
    }
    
    List<DailyMeal> dailyMeals = weeklyPlan.getDailyMeals();
    double weeklyTotalCalories = 0.0;
    double weeklyTotalProtein = 0.0;
    double weeklyTotalFat = 0.0;
    double weeklyTotalCarbohydrate = 0.0;
    
    for (DailyMeal dailyMeal : dailyMeals) {
        double dailyCalories = 0.0;
        double dailyProtein = 0.0;
        double dailyFat = 0.0;
        double dailyCarbohydrate = 0.0;
        
        List<Integer> breakfastRecipes = dailyMeal.getBreakfastRecipes();
        List<Integer> lunchRecipes = dailyMeal.getLunchRecipes();
        List<Integer> dinnerRecipes = dailyMeal.getDinnerRecipes();
        
        for (Integer recipeId : breakfastRecipes) {
            Recipe recipe = recipeMapper.findById(recipeId);
            if (recipe != null) {
                dailyCalories += recipe.getTotalCalories();
                dailyProtein += recipe.getTotalProtein();
                dailyFat += recipe.getTotalFat();
                dailyCarbohydrate += recipe.getTotalCarbohydrate();
            }
        }
        
        for (Integer recipeId : lunchRecipes) {
            Recipe recipe = recipeMapper.findById(recipeId);
            if (recipe != null) {
                dailyCalories += recipe.getTotalCalories();
                dailyProtein += recipe.getTotalProtein();
                dailyFat += recipe.getTotalFat();
                dailyCarbohydrate += recipe.getTotalCarbohydrate();
            }
        }
        
        for (Integer recipeId : dinnerRecipes) {
            Recipe recipe = recipeMapper.findById(recipeId);
            if (recipe != null) {
                dailyCalories += recipe.getTotalCalories();
                dailyProtein += recipe.getTotalProtein();
                dailyFat += recipe.getTotalFat();
                dailyCarbohydrate += recipe.getTotalCarbohydrate();
            }
        }
        
        dailyMeal.setDailyCalories(dailyCalories);
        dailyMeal.setDailyProtein(dailyProtein);
        dailyMeal.setDailyFat(dailyFat);
        dailyMeal.setDailyCarbohydrate(dailyCarbohydrate);
        
        weeklyTotalCalories += dailyCalories;
        weeklyTotalProtein += dailyProtein;
        weeklyTotalFat += dailyFat;
        weeklyTotalCarbohydrate += dailyCarbohydrate;
    }
    
    weeklyPlan.setWeeklyTotalCalories(weeklyTotalCalories);
    weeklyPlan.setWeeklyTotalProtein(weeklyTotalProtein);
    weeklyPlan.setWeeklyTotalFat(weeklyTotalFat);
    weeklyPlan.setWeeklyTotalCarbohydrate(weeklyTotalCarbohydrate);
    weeklyPlan.setCreateTime(new Date());
    
    int result = weeklyPlanMapper.insert(weeklyPlan);
    if (result > 0) {
        for (DailyMeal dailyMeal : dailyMeals) {
            dailyMeal.setWeeklyPlanId(weeklyPlan.getId());
            dailyMealMapper.insert(dailyMeal);
        }
        response.put("success", true);
        response.put("message", "周食谱安排创建成功");
        response.put("planId", weeklyPlan.getId());
        return ResponseEntity.ok(response);
    } else {
        response.put("success", false);
        response.put("message", "周食谱安排创建失败");
        return ResponseEntity.status(500).body(response);
    }
}

// 美食论坛核心业务处理
@PostMapping("/publishPost")
public ResponseEntity<Map<String, Object>> publishPost(@RequestBody ForumPost forumPost) {
    Map<String, Object> response = new HashMap<>();
    
    if (forumPost.getTitle() == null || forumPost.getTitle().trim().isEmpty()) {
        response.put("success", false);
        response.put("message", "帖子标题不能为空");
        return ResponseEntity.badRequest().body(response);
    }
    
    if (forumPost.getContent() == null || forumPost.getContent().trim().isEmpty()) {
        response.put("success", false);
        response.put("message", "帖子内容不能为空");
        return ResponseEntity.badRequest().body(response);
    }
    
    if (forumPost.getUserId() == null) {
        response.put("success", false);
        response.put("message", "用户信息异常");
        return ResponseEntity.badRequest().body(response);
    }
    
    String sensitiveWords = sensitiveWordService.checkSensitiveWords(forumPost.getTitle() + " " + forumPost.getContent());
    if (sensitiveWords != null) {
        response.put("success", false);
        response.put("message", "内容包含敏感词汇: " + sensitiveWords);
        return ResponseEntity.badRequest().body(response);
    }
    
    User user = userMapper.findById(forumPost.getUserId());
    if (user == null) {
        response.put("success", false);
        response.put("message", "用户不存在");
        return ResponseEntity.badRequest().body(response);
    }
    
    forumPost.setAuthorName(user.getUsername());
    forumPost.setCreateTime(new Date());
    forumPost.setUpdateTime(new Date());
    forumPost.setViewCount(0);
    forumPost.setLikeCount(0);
    forumPost.setCommentCount(0);
    forumPost.setStatus(1);
    
    if (forumPost.getImages() != null && !forumPost.getImages().isEmpty()) {
        List<String> validImages = new ArrayList<>();
        for (String imageUrl : forumPost.getImages()) {
            if (imageUrl != null && !imageUrl.trim().isEmpty()) {
                if (imageService.validateImageUrl(imageUrl)) {
                    validImages.add(imageUrl);
                }
            }
        }
        forumPost.setImages(validImages);
    }
    
    if (forumPost.getTags() != null && !forumPost.getTags().isEmpty()) {
        List<String> processedTags = new ArrayList<>();
        for (String tag : forumPost.getTags()) {
            if (tag != null && !tag.trim().isEmpty()) {
                tag = tag.trim().replace("#", "");
                if (tag.length() <= 20) {
                    processedTags.add(tag);
                }
            }
        }
        forumPost.setTags(processedTags);
    }
    
    int result = forumPostMapper.insert(forumPost);
    if (result > 0) {
        user.setPostCount(user.getPostCount() + 1);
        userMapper.update(user);
        
        response.put("success", true);
        response.put("message", "帖子发布成功");
        response.put("postId", forumPost.getId());
        return ResponseEntity.ok(response);
    } else {
        response.put("success", false);
        response.put("message", "帖子发布失败");
        return ResponseEntity.status(500).body(response);
    }
}

六、基于SpringBoot的食谱健康管理系统-文档展示

在这里插入图片描述

七、END

wechat_2025-08-07_155405_686.png

💕💕文末获取源码联系计算机编程果茶熊