基于SpringBoot的美食分享平台-038

一、项目技术栈

Java开发工具:JDK1.8
后端框架:SpringBoot
前端:采用HTML和Vue相结合开发
数据库:MySQL5.7和Navicat管理工具结合
服务器:Tomcat8.5
开发软件:IDEA / Eclipse
是否Maven项目:是

二、功能介绍

三、项目视频

基于SpringBoot的美食分享平台-038

四、功能截图
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

五、代码实现
账户信息

package com.example.controller;import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.Account;
import com.example.entity.AuthorityInfo;
import com.example.exception.CustomException;
import com.example.entity.AdminInfo;
import com.example.entity.UserInfo;import com.example.service.AdminInfoService;
import com.example.service.UserInfoService;import org.springframework.web.bind.annotation.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import cn.hutool.json.JSONUtil;import java.util.*;
import java.util.stream.Collectors;@RestController
public class AccountController {@Value("${authority.info}")private String authorityStr;@Resourceprivate AdminInfoService adminInfoService;@Resourceprivate UserInfoService userInfoService;@PostMapping("/login")public Result<Account> login(@RequestBody Account account, HttpServletRequest request) {if (StrUtil.isBlank(account.getName()) || StrUtil.isBlank(account.getPassword()) || account.getLevel() == null) {throw new CustomException(ResultCode.PARAM_LOST_ERROR);}Integer level = account.getLevel();Account login = new Account();if (1 == level) {login = adminInfoService.login(account.getName(), account.getPassword());}if (2 == level) {login = userInfoService.login(account.getName(), account.getPassword());}request.getSession().setAttribute("user", login);return Result.success(login);}@PostMapping("/register")public Result<Account> register(@RequestBody Account account) {Integer level = account.getLevel();Account login = new Account();if (1 == level) {AdminInfo info = new AdminInfo();BeanUtils.copyProperties(account, info);login = adminInfoService.add(info);}if (2 == level) {UserInfo info = new UserInfo();BeanUtils.copyProperties(account, info);login = userInfoService.add(info);}return Result.success(login);}@GetMapping("/logout")public Result logout(HttpServletRequest request) {request.getSession().setAttribute("user", null);return Result.success();}@GetMapping("/auth")public Result getAuth(HttpServletRequest request) {Object user = request.getSession().getAttribute("user");if(user == null) {return Result.error("401", "未登录");}return Result.success(user);}@GetMapping("/getAccountInfo")public Result<Object> getAccountInfo(HttpServletRequest request) {Account account = (Account) request.getSession().getAttribute("user");if (account == null) {return Result.success(new Object());}Integer level = account.getLevel();if (1 == level) {return Result.success(adminInfoService.findById(account.getId()));}if (2 == level) {return Result.success(userInfoService.findById(account.getId()));}return Result.success(new Object());}@GetMapping("/getSession")public Result<Map<String, String>> getSession(HttpServletRequest request) {Account account = (Account) request.getSession().getAttribute("user");if (account == null) {return Result.success(new HashMap<>(1));}Map<String, String> map = new HashMap<>(1);map.put("username", account.getName());return Result.success(map);}@GetMapping("/getAuthority")public Result<List<AuthorityInfo>> getAuthorityInfo() {List<AuthorityInfo> authorityInfoList = JSONUtil.toList(JSONUtil.parseArray(authorityStr), AuthorityInfo.class);return Result.success(authorityInfoList);}/*** 获取当前用户所能看到的模块信息* @param request* @return*/@GetMapping("/authority")public Result<List<Integer>> getAuthorityInfo(HttpServletRequest request) {Account user = (Account) request.getSession().getAttribute("user");if (user == null) {return Result.success(new ArrayList<>());}JSONArray objects = JSONUtil.parseArray(authorityStr);for (Object object : objects) {JSONObject jsonObject = (JSONObject) object;if (user.getLevel().equals(jsonObject.getInt("level"))) {JSONArray array = JSONUtil.parseArray(jsonObject.getStr("models"));List<Integer> modelIdList = array.stream().map((o -> {JSONObject obj = (JSONObject) o;return obj.getInt("modelId");})).collect(Collectors.toList());return Result.success(modelIdList);}}return Result.success(new ArrayList<>());}@GetMapping("/permission/{modelId}")public Result<List<Integer>> getPermission(@PathVariable Integer modelId, HttpServletRequest request) {List<AuthorityInfo> authorityInfoList = JSONUtil.toList(JSONUtil.parseArray(authorityStr), AuthorityInfo.class);Account user = (Account) request.getSession().getAttribute("user");if (user == null) {return Result.success(new ArrayList<>());}Optional<AuthorityInfo> optional = authorityInfoList.stream().filter(x -> x.getLevel().equals(user.getLevel())).findFirst();if (optional.isPresent()) {Optional<AuthorityInfo.Model> firstOption = optional.get().getModels().stream().filter(x -> x.getModelId().equals(modelId)).findFirst();if (firstOption.isPresent()) {List<Integer> info = firstOption.get().getOperation();return Result.success(info);}}return Result.success(new ArrayList<>());}@PutMapping("/updatePassword")public Result updatePassword(@RequestBody Account info, HttpServletRequest request) {Account account = (Account) request.getSession().getAttribute("user");if (account == null) {return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg);}String oldPassword = SecureUtil.md5(info.getPassword());if (!oldPassword.equals(account.getPassword())) {return Result.error(ResultCode.PARAM_PASSWORD_ERROR.code, ResultCode.PARAM_PASSWORD_ERROR.msg);}info.setPassword(SecureUtil.md5(info.getNewPassword()));Integer level = account.getLevel();if (1 == level) {AdminInfo adminInfo = new AdminInfo();BeanUtils.copyProperties(info, adminInfo);adminInfoService.update(adminInfo);}if (2 == level) {UserInfo userInfo = new UserInfo();BeanUtils.copyProperties(info, userInfo);userInfoService.update(userInfo);}info.setLevel(level);info.setName(account.getName());// 清空session,让用户重新登录request.getSession().setAttribute("user", null);return Result.success();}@PostMapping("/resetPassword")public Result resetPassword(@RequestBody Account account) {Integer level = account.getLevel();if (1 == level) {AdminInfo info = adminInfoService.findByUserName(account.getName());if (info == null) {return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg);}info.setPassword(SecureUtil.md5("123456"));adminInfoService.update(info);}if (2 == level) {UserInfo info = userInfoService.findByUserName(account.getName());if (info == null) {return Result.error(ResultCode.USER_NOT_EXIST_ERROR.code, ResultCode.USER_NOT_EXIST_ERROR.msg);}info.setPassword(SecureUtil.md5("123456"));userInfoService.update(info);}return Result.success();}
}

留言信息

package com.example.controller;import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.MessageInfo;
import com.example.service.*;
import com.example.vo.MessageInfoVo;import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;@RestController
@RequestMapping(value = "/messageInfo")
public class MessageInfoController {@Resourceprivate MessageInfoService messageInfoService;@PostMappingpublic Result<MessageInfo> add(@RequestBody MessageInfoVo messageInfo) {messageInfoService.add(messageInfo);return Result.success(messageInfo);}@DeleteMapping("/{id}")public Result delete(@PathVariable Long id) {messageInfoService.delete(id);return Result.success();}@PutMappingpublic Result update(@RequestBody MessageInfoVo messageInfo) {messageInfoService.update(messageInfo);return Result.success();}@GetMapping("/{id}")public Result<MessageInfo> detail(@PathVariable Long id) {MessageInfo messageInfo = messageInfoService.findById(id);return Result.success(messageInfo);}@GetMappingpublic Result<List<MessageInfoVo>> all() {return Result.success(messageInfoService.findAll());}@GetMapping("/page/{name}")public Result<PageInfo<MessageInfoVo>> page(@PathVariable String name,@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize,HttpServletRequest request) {return Result.success(messageInfoService.findPage(name, pageNum, pageSize, request));}/*** 批量通过excel添加信息* @param file excel文件* @throws IOException*/@PostMapping("/upload")public Result upload(MultipartFile file) throws IOException {List<MessageInfo> infoList = ExcelUtil.getReader(file.getInputStream()).readAll(MessageInfo.class);if (!CollectionUtil.isEmpty(infoList)) {// 处理一下空数据List<MessageInfo> resultList = infoList.stream().filter(x -> ObjectUtil.isNotEmpty(x.getName())).collect(Collectors.toList());for (MessageInfo info : resultList) {messageInfoService.add(info);}}return Result.success();}@GetMapping("/getExcelModel")public void getExcelModel(HttpServletResponse response) throws IOException {// 1. 生成excelMap<String, Object> row = new LinkedHashMap<>();row.put("name", "小李");row.put("content", "来了");row.put("time", "TIME");List<Map<String, Object>> list = CollUtil.newArrayList(row);// 2. 写excelExcelWriter writer = ExcelUtil.getWriter(true);writer.write(list, true);response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");response.setHeader("Content-Disposition","attachment;filename=messageInfoModel.xlsx");ServletOutputStream out = response.getOutputStream();writer.flush(out, true);writer.close();IoUtil.close(System.out);}
}

公告信息

package com.example.controller;import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.io.IoUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.example.common.Result;
import com.example.common.ResultCode;
import com.example.entity.NewsInfo;
import com.example.service.*;
import com.example.vo.NewsInfoVo;import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;@RestController
@RequestMapping(value = "/newsInfo")
public class NewsInfoController {@Resourceprivate NewsInfoService newsInfoService;@PostMappingpublic Result<NewsInfo> add(@RequestBody NewsInfoVo newsInfo) {newsInfoService.add(newsInfo);return Result.success(newsInfo);}@DeleteMapping("/{id}")public Result delete(@PathVariable Long id) {newsInfoService.delete(id);return Result.success();}@PutMappingpublic Result update(@RequestBody NewsInfoVo newsInfo) {newsInfoService.update(newsInfo);return Result.success();}@GetMapping("/{id}")public Result<NewsInfo> detail(@PathVariable Long id) {NewsInfo newsInfo = newsInfoService.findById(id);return Result.success(newsInfo);}@GetMappingpublic Result<List<NewsInfoVo>> all() {return Result.success(newsInfoService.findAll());}@GetMapping("/page/{name}")public Result<PageInfo<NewsInfoVo>> page(@PathVariable String name,@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "5") Integer pageSize,HttpServletRequest request) {return Result.success(newsInfoService.findPage(name, pageNum, pageSize, request));}/*** 批量通过excel添加信息* @param file excel文件* @throws IOException*/@PostMapping("/upload")public Result upload(MultipartFile file) throws IOException {List<NewsInfo> infoList = ExcelUtil.getReader(file.getInputStream()).readAll(NewsInfo.class);if (!CollectionUtil.isEmpty(infoList)) {// 处理一下空数据List<NewsInfo> resultList = infoList.stream().filter(x -> ObjectUtil.isNotEmpty(x.getName())).collect(Collectors.toList());for (NewsInfo info : resultList) {newsInfoService.add(info);}}return Result.success();}@GetMapping("/getExcelModel")public void getExcelModel(HttpServletResponse response) throws IOException {// 1. 生成excelMap<String, Object> row = new LinkedHashMap<>();row.put("name", "");row.put("content", "");List<Map<String, Object>> list = CollUtil.newArrayList(row);// 2. 写excelExcelWriter writer = ExcelUtil.getWriter(true);writer.write(list, true);response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8");response.setHeader("Content-Disposition","attachment;filename=newsInfoModel.xlsx");ServletOutputStream out = response.getOutputStream();writer.flush(out, true);writer.close();IoUtil.close(System.out);}
}

HadesTYT 上万套源码,每日分享源码,谢谢你的关注和喜欢,需要可以联系主页信息。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如若转载,请注明出处:http://www.pswp.cn/pingmian/85166.shtml
繁体地址,请注明出处:http://hk.pswp.cn/pingmian/85166.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【C++第三方包安装】Windows与Linux安装配置redis-plus-plus指南

前言 下面主要是对于两种环境安装、配置、使用C的第三方包&#xff08;redis&#xff09;&#xff0c;对于其他的第三方库&#xff0c;也可以使用类似的方法进行类比安装。 且大多数的第三方库都可以利用工具一键安装或手动编译安装。 Windows 要在Windows系统上快速安装和使…

springboot入门之路(二)

系列文章目录 springboot入门之路&#xff08;一&#xff09;连续的学习渐进之路。阅读点击&#xff1a;springboot入门之路(一) 文章目录 系列文章目录3.springboot配置及注意事项3.1继承starter parent3.2使用没有父POM的Spring Boot3.3配置java的编译的版本3.4使用"de…

【开源解析】基于Python+Qt打造智能应用时长统计工具 - 你的数字生活分析师

&#x1f4ca; 【开源解析】基于PythonQt打造智能应用时长统计工具 - 你的数字生活分析师 &#x1f308; 个人主页&#xff1a;创客白泽 - CSDN博客 &#x1f525; 系列专栏&#xff1a;&#x1f40d;《Python开源项目实战》 &#x1f4a1; 热爱不止于代码&#xff0c;热情源自…

PHP语法基础篇(三):类型转换与常量

"在完成PHP输出函数和字符串操作的学习后&#xff0c;本篇笔记将记录 类型转换和 常量应用的学习过程。作为语法基础篇的第三部分&#xff0c;将重点关注&#xff1a; 类型转换数学函数常量定义&#xff1a;define() 与const 的使用差异魔术常量应用&#xff1a;__LINE__ …

Linux lsof 命令详解+实例

&#x1f468;‍&#x1f393;博主简介 &#x1f3c5;CSDN博客专家   &#x1f3c5;云计算领域优质创作者   &#x1f3c5;华为云开发者社区专家博主   &#x1f3c5;阿里云开发者社区专家博主 &#x1f48a;交流社区&#xff1a;运维交流社区 欢迎大家的加入&#xff01…

【Cobalt Strike手册】客户端界面功能

工具栏 顶部的工具栏提供了快速访问的功能&#xff0c;这些图片的功能从左到右功能以此如下表 创建新的连接断开当前的TeamServerListeners监听器列表以图形化展示表格形式展示表格展示目标管理Web服务查看获取到的认证信息查看下载的文件查看键盘记录查看截屏记录 图形化会话…

FastAPI本地文档的定制技巧

磨刀不误砍柴工&#xff0c;一份清晰的API文档能让前后端协作效率翻倍——源滚滚如是说 在前后端分离开发的今天&#xff0c;接口文档的质量直接决定了团队协作的效率。作为Python领域最受瞩目的现代Web框架&#xff0c;FastAPI最大的亮点之一是其自动化交互式文档功能。但很多…

Python 标准库概览

Python 标准库非常庞大,所提供的组件涉及范围十分广泛,使用标准库我们可以让您轻松地完成各种任务。 以下是一些 Python3 标准库中的模块: os 模块:os 模块提供了许多与操作系统交互的函数,例如创建、移动和删除文件和目录,以及访问环境变量等。 sys 模块:sys 模块提供…

AI大模型:(二)4.1 文生图(Text-to-Image)模型发展史

目录 1.介绍 2.发展历史 2.1.早期探索阶段(1980-2014 年) 2.1.1.卷积神经网络(CNN) 2.1.2.生成对抗网络(GAN)的提出 2.2.GAN主导时代(2015-2018 年) 2.2.1.高分辨率GAN的突破 2.2.2.文本-图像对齐的改进 2.3. Diffusion革命(2021–2022) 2.3.1.扩散模型(D…

vue3实现轮播渲染多张图每张进行放大缩小拖拽功能互不影响

vue3实现轮播渲染多张图每张进行放大缩小拖拽功能互不影响 1.以vue3中el-carousel轮播插件为例 <div class"pic_view"><el-carousel height"100vh" :autoplay"false" ref"carouselRef" change"handleCarouselChange&qu…

traceroute 使用说明

1、概述 Traceroute&#xff08;Windows 系统中为 tracert&#xff09;是一种网络诊断工具&#xff0c;用于跟踪数据包从本地设备到目标主机的传输路径&#xff0c;并显示沿途经过的每一跳&#xff08;路由器&#xff09;的延迟和 IP 地址。它通过发送不同 TTL&#xff08;生存…

用idea操作git缓存区回退、本地库回退、远程库回退

前言 使用idea软件操作git非常人性化和方便。 但是如果我的代码使用git提交之后,我想回到以前的版本,此时需要进行git的版本回退。 提交代码分为提交到缓存区、本地库、远程库这3个过程。 下面我将介绍每个阶段的提交对应的回退方法。 本篇文章是掌握git和使用idea操作git…

webpack+vite前端构建工具 - 3webpack处理js

3 webpack处理js webpack的核心——处理js文件&#xff0c;将模块化的代码打包。具体操作如下 es6转化&#xff08;为兼容老浏览器&#xff0c;将es6转化为es5&#xff09; babel-loader 代码规范&#xff08;例如空格&#xff0c;缩进等代码风格规范&#xff09; eslint 代码…

Nginx转发中相对路径资源302问题的分析与解决

Nginx转发中相对路径资源302问题的分析与解决 典型案例&#xff1a;后端页面引入./test.css的302问题 问题场景 假设我们有一个后端服务&#xff0c;其页面中通过相对路径引入了CSS文件&#xff1a; <!-- 后端页面代码 --> <link rel"stylesheet" href&…

Vue3 + TypeScript合并两个列表到目标列表,并且进行排序,数组合并、集合合并、列表合并、list合并

在Vue 3 TypeScript中合并并排序两个列表&#xff0c;可以通过以下步骤实现&#xff1a; 解决方案代码 vue 复制 下载 <script setup lang"ts"> import { ref, computed } from vue;// 定义列表项类型 interface ListItem {id: number;name: string;valu…

Python-教程

1 需求 2 接口 3 示例 4 参考资料 Python 教程 — Python 3.13.5 文档

Excel数据导出小记

文章目录 前言一、DataTable >EXCEL二、DBReader >Excel &#xff08;NPOI&#xff09;三、分页查询 DbReader>Excel (MiniExcel)总结&#xff1a; 前言 最近经历了一次数据量比较大的导出&#xff0c;也做了各种优化尝试&#xff0c;这里稍记录一下 一、DataTable …

深入理解链表数据结构:从Java LinkedList到自定义实现

引言 链表作为基础数据结构之一&#xff0c;在Java集合框架中以LinkedList的形式提供。本文将深入分析Java原生LinkedList的实现机制&#xff0c;并介绍我自定义实现的MyLinkedList&#xff0c;最后对比两者的设计差异与实现特点。 Java原生LinkedList解析 基本结构 Java的…

【深度学习】卷积神经网络(CNN):计算机视觉的革命性引擎

卷积神经网络&#xff08;CNN&#xff09;&#xff1a;计算机视觉的革命性引擎 一、算法背景&#xff1a;视觉智能的进化之路1.1 传统视觉处理的困境1.2 神经科学的启示 二、算法理论&#xff1a;CNN的核心架构2.1 基础组成单元卷积层&#xff1a;特征提取引擎池化层&#xff1…

使用@SpringJUnitConfig注解开发遇到的空指针问题

Spring测试中的版本陷阱&#xff1a;SpringJUnitConfig与JUnit版本兼容性深度解析 一个看似简单的空指针异常&#xff0c;背后可能隐藏着JUnit版本不匹配的“幽灵”。 一、SpringJUnitConfig&#xff1a;Spring与JUnit 5的桥梁 SpringJUnitConfig是Spring TestContext框架为**…