1. 项目背景与核心价值
去年帮学弟调试毕业设计时,发现美食类管理系统存在两个普遍痛点:一是传统SSM架构配置文件繁杂,二是前后端耦合度高导致调试困难。这个基于SpringBoot的美食分享平台管理系统,采用前后端分离架构,用Vue.js+ElementUI实现管理后台,通过RESTful API与后端交互,特别适合作为Java全栈开发的入门实战项目。
系统最实用的功能点是"智能菜谱推荐"模块,通过用户收藏行为分析口味偏好。有毕业生凭借这个亮点拿到了美团点评的校招offer,可见这类项目在求职时的加分效果。
2. 技术栈选型解析
2.1 后端技术组合
SpringBoot 2.7 + MyBatis-Plus 3.5 + Lombok + Hutool工具包构成核心框架。选择MyBatis-Plus而非JPA是考虑到:
- 需要复杂SQL查询(如多表联查菜谱收藏量)
- 项目存在历史SQL需要复用
- 对数据库字段有精细控制需求
数据库采用MySQL 8.0,配置了连接池:
spring: datasource: url: jdbc:mysql://localhost:3306/food_share?useSSL=false&serverTimezone=Asia/Shanghai username: root password: 123456 hikari: maximum-pool-size: 20 minimum-idle: 52.2 前端技术方案
Vue 3 + Element Plus + Axios构成管理后台,采用如下路由配置:
const routes = [ { path: '/', component: Layout, redirect: '/dashboard', children: [{ path: 'dashboard', component: () => import('@/views/dashboard/index'), meta: { title: '首页', icon: 'dashboard' } }] }, { path: '/recipe', component: Layout, redirect: '/recipe/list', meta: { title: '菜谱管理', icon: 'el-icon-food' }, children: [ { path: 'list', component: () => import('@/views/recipe/list'), meta: { title: '菜谱列表' } } ] } ]3. 核心模块实现细节
3.1 智能推荐算法
在RecipeServiceImpl中实现基于用户的协同过滤:
public List<RecipeVO> recommendRecipes(Long userId) { // 1. 获取用户收藏记录 List<Collect> collects = collectMapper.selectList( new QueryWrapper<Collect>().eq("user_id", userId)); // 2. 找出相似用户 List<Long> similarUsers = findSimilarUsers(collects); // 3. 加权计算推荐菜品 return recipeMapper.selectRecommendRecipes(similarUsers); }3.2 权限控制方案
采用RBAC模型,通过自定义注解实现:
@Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) public @interface RequiresPermissions { String[] value(); } // AOP权限校验 @Around("@annotation(requiresPermissions)") public Object around(ProceedingJoinPoint joinPoint, RequiresPermissions requiresPermissions) throws Throwable { String[] permissions = requiresPermissions.value(); if (!hasPermissions(permissions)) { throw new ForbiddenException("无操作权限"); } return joinPoint.proceed(); }4. 典型问题解决方案
4.1 文件上传异常
常见报错:MultipartException: Current request is not a multipart request解决方案:
- 检查前端FormData格式
- 确认配置文件中已启用multipart:
spring: servlet: multipart: max-file-size: 10MB max-request-size: 20MB4.2 MyBatis缓存问题
现象:更新数据后查询结果未刷新 处理方法:
@CacheEvict(value = "recipeCache", key = "#recipe.id") public void updateRecipe(Recipe recipe) { recipeMapper.updateById(recipe); }5. 项目部署指南
5.1 生产环境配置
Nginx反向代理配置示例:
server { listen 80; server_name foodshare.example.com; location /api { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; } location / { root /var/www/html/dist; try_files $uri $uri/ /index.html; } }5.2 性能优化建议
- 数据库添加索引:
ALTER TABLE `recipe` ADD INDEX `idx_category` (`category_id`);- 启用Gzip压缩:
server: compression: enabled: true mime-types: text/html,text/xml,text/plain,application/json6. 毕业设计扩展建议
- 增加Elasticsearch实现菜谱搜索
- 集成Redis缓存热门菜谱
- 添加微信小程序端
- 实现食材库存管理功能
- 开发美食短视频模块
这个项目我在GitHub上维护了持续更新的分支,包含Docker部署脚本和Swagger接口文档。调试时遇到问题可以查看issue区,常见问题都有解决方案。特别提醒:数据库字符集要设为utf8mb4,否则会遇到emoji存储异常。