首页 > 数据库 >基于Java+Spring Boot+MySQL的智能菜谱推荐

基于Java+Spring Boot+MySQL的智能菜谱推荐

时间:2024-03-14 20:59:53浏览次数:31  
标签:Java Spring org Boot return user import new public

目录

前言

 一、技术栈

二、系统功能介绍

三、核心代码

1、登录模块

 2、文件上传模块

3、代码封装


前言

近些年来,随着科技的飞速发展,互联网的普及逐渐延伸到各行各业中,给人们生活带来了十分的便利,智能菜谱推荐系统利用计算机网络实现信息化管理,使整个智能菜谱推荐管理的发展和服务水平有显著提升。

本文拟采用java技术和Springboot 搭建系统框架,后台使用MySQL数据库进行信息管理,设计开发的智能菜谱推荐系统。通过调研和分析,系统拥有管理员和用户两个角色,主要具备登录注册、个人信息修改、对用户管理、类型管理、菜谱信息管理、评分信息管理、留言信息、系统管理等功能进行操作。将纸质管理有效实现为在线管理,极大提高工作效率。

 一、技术栈

末尾获取源码
Spring Boot+JS+ jQuery+Ajax...

二、系统功能介绍

当人们打开系统的网址后,首先看到的就是首页界面。在这里,人们能够看到系统的导航条,通过导航条导航进入各功能展示页面进行操作。系统首页界面如图5-1所示:

 

系统注册:在系统注册页面的输入栏中输入用户注册信息进行注册操作,系统注册页面如图5-2所示: 

 

菜谱信息:在菜谱信息页面的输入菜谱名称、口味、烹饪方式和选择类型进行查询菜谱详细信息;并根据需要对菜谱详细信息进行评分、评论或收藏操作;菜谱详细信息页面如图5-3所示: 

 

留言板:在留言板页面通过输入留言内容,上传图片并立即提交进行在线留言,还可以对留言内容进行回复操作;留言板页面如图5-4所示: 

 

个人中心;在个人中心页面可以输入个人详细信息进行信息更新操作,还可以对我的收藏进行详细操作;如图5-5所示: 

 

管理员登录,在登录页面正确输入用户名和密码后,点击登录进入操作系统进行操作;如图5-6所示。  

 

管理员进入主页面,主要功能包括对个人中心、用户管理、类型管理、菜谱信息管理、评分信息管理、留言信息、系统管理等进行操作。管理员主页面如图5-7所示: 

 

管理员点击用户管理。进入用户页面输入账号和姓名进行查询、新增和删除用户列表,并根据需要对用户详细信息进行详情,修改和删除操作;如图5-8所示: 

 

管理员点击菜谱信息管理。进入菜谱信息页面输入菜谱名称、口味、烹饪方式和选择类型进行查询、菜谱分类统计、菜谱评分统计、新增或删除菜谱信息列表,并根据需要对菜谱详细信息进行详情、评分、查看评论、修改或删除操作;如图5-9所示: 

 

管理员点击评分信息管理。进入评分信息页面输入菜谱名称和类型进行查询、每日评分人数统计或删除评分信息列表,并根据需要对评分详细信息进行详情或删除操作;如图5-10所示: 

 

管理员点击留言信息管理。进入留言信息页面输入用户名进行查询和删除留言信息列表,并根据需要对留言详细信息进行详情、回复或删除操作;如图5-11所示: 

 

管理员点击系统管理可以对关于我们、系统简介和轮播图管理进行查看详情或修改操作,在公告信息页面输入标题进行查询,新增或删除公告信息列表,并根据需要对公告详细信息进行详情,修改和删除操作;如图5-12所示: 

 

三、核心代码

1、登录模块

 
package com.controller;
 
 
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
 
import javax.servlet.http.HttpServletRequest;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
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.bind.annotation.RestController;
 
import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.TokenEntity;
import com.entity.UserEntity;
import com.service.TokenService;
import com.service.UserService;
import com.utils.CommonUtil;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.ValidatorUtils;
 
/**
 * 登录相关
 */
@RequestMapping("users")
@RestController
public class UserController{
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private TokenService tokenService;
 
	/**
	 * 登录
	 */
	@IgnoreAuth
	@PostMapping(value = "/login")
	public R login(String username, String password, String captcha, HttpServletRequest request) {
		UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
		if(user==null || !user.getPassword().equals(password)) {
			return R.error("账号或密码不正确");
		}
		String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
		return R.ok().put("token", token);
	}
	
	/**
	 * 注册
	 */
	@IgnoreAuth
	@PostMapping(value = "/register")
	public R register(@RequestBody UserEntity user){
//    	ValidatorUtils.validateEntity(user);
    	if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
    		return R.error("用户已存在");
    	}
        userService.insert(user);
        return R.ok();
    }
 
	/**
	 * 退出
	 */
	@GetMapping(value = "logout")
	public R logout(HttpServletRequest request) {
		request.getSession().invalidate();
		return R.ok("退出成功");
	}
	
	/**
     * 密码重置
     */
    @IgnoreAuth
	@RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request){
    	UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
    	if(user==null) {
    		return R.error("账号不存在");
    	}
    	user.setPassword("123456");
        userService.update(user,null);
        return R.ok("密码已重置为:123456");
    }
	
	/**
     * 列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,UserEntity user){
        EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
    	PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
        return R.ok().put("data", page);
    }
 
	/**
     * 列表
     */
    @RequestMapping("/list")
    public R list( UserEntity user){
       	EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
      	ew.allEq(MPUtil.allEQMapPre( user, "user")); 
        return R.ok().put("data", userService.selectListView(ew));
    }
 
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        UserEntity user = userService.selectById(id);
        return R.ok().put("data", user);
    }
    
    /**
     * 获取用户的session用户信息
     */
    @RequestMapping("/session")
    public R getCurrUser(HttpServletRequest request){
    	Long id = (Long)request.getSession().getAttribute("userId");
        UserEntity user = userService.selectById(id);
        return R.ok().put("data", user);
    }
 
    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserEntity user){
//    	ValidatorUtils.validateEntity(user);
    	if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
    		return R.error("用户已存在");
    	}
        userService.insert(user);
        return R.ok();
    }
 
    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
//        ValidatorUtils.validateEntity(user);
        userService.updateById(user);//全部更新
        return R.ok();
    }
 
    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        userService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}

 2、文件上传模块

package com.controller;
 
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;
 
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
 
import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.ConfigEntity;
import com.entity.EIException;
import com.service.ConfigService;
import com.utils.R;
 
/**
 * 上传文件映射表
 */
@RestController
@RequestMapping("file")
@SuppressWarnings({"unchecked","rawtypes"})
public class FileController{
	@Autowired
    private ConfigService configService;
	/**
	 * 上传文件
	 */
	@RequestMapping("/upload")
	public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
		if (file.isEmpty()) {
			throw new EIException("上传文件不能为空");
		}
		String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
		File path = new File(ResourceUtils.getURL("classpath:static").getPath());
		if(!path.exists()) {
		    path = new File("");
		}
		File upload = new File(path.getAbsolutePath(),"/upload/");
		if(!upload.exists()) {
		    upload.mkdirs();
		}
		String fileName = new Date().getTime()+"."+fileExt;
		File dest = new File(upload.getAbsolutePath()+"/"+fileName);
		file.transferTo(dest);
		FileUtils.copyFile(dest, new File("C:\\Users\\Desktop\\jiadian\\springbootl7own\\src\\main\\resources\\static\\upload"+"/"+fileName));
		if(StringUtils.isNotBlank(type) && type.equals("1")) {
			ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
			if(configEntity==null) {
				configEntity = new ConfigEntity();
				configEntity.setName("faceFile");
				configEntity.setValue(fileName);
			} else {
				configEntity.setValue(fileName);
			}
			configService.insertOrUpdate(configEntity);
		}
		return R.ok().put("file", fileName);
	}
	
	/**
	 * 下载文件
	 */
	@IgnoreAuth
	@RequestMapping("/download")
	public ResponseEntity<byte[]> download(@RequestParam String fileName) {
		try {
			File path = new File(ResourceUtils.getURL("classpath:static").getPath());
			if(!path.exists()) {
			    path = new File("");
			}
			File upload = new File(path.getAbsolutePath(),"/upload/");
			if(!upload.exists()) {
			    upload.mkdirs();
			}
			File file = new File(upload.getAbsolutePath()+"/"+fileName);
			if(file.exists()){
				/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
					getResponse().sendError(403);
				}*/
				HttpHeaders headers = new HttpHeaders();
			    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);    
			    headers.setContentDispositionFormData("attachment", fileName);    
			    return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
	}
	
}

3、代码封装

package com.utils;
 
import java.util.HashMap;
import java.util.Map;
 
/**
 * 返回数据
 */
public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public R() {
		put("code", 0);
	}
	
	public static R error() {
		return error(500, "未知异常,请联系管理员");
	}
	
	public static R error(String msg) {
		return error(500, msg);
	}
	
	public static R error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}
 
	public static R ok(String msg) {
		R r = new R();
		r.put("msg", msg);
		return r;
	}
	
	public static R ok(Map<String, Object> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}
	
	public static R ok() {
		return new R();
	}
 
	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}

标签:Java,Spring,org,Boot,return,user,import,new,public
From: https://blog.csdn.net/2301_77541824/article/details/136666474

相关文章

  • 真炸裂,发现一款基于springboot超级好用的开源服务器框架
    兄弟们,真不骗你们,这个框架用起来是真的爽,简直是服务器开发人员的福音!集成该项目后,不用我们程序员再去处理api安全、加签、验签、参数校验、加解密、数据脱敏、异常处理、国际化、接口文档、错误码、缓存、分布式锁、应用、渠道管理等等功能。而且为了帮助客户端开发的同学更简......
  • SpringMVC
    概述SpringMVC是基于MVC模式开发的框架,用来优化Controller,具备IoC和AOP[[Spring#分层解耦|MVC]]是一种开发模式,是模式-视图-控制器的简称,所有的web应用都是基于MVC开发的。SpringMVC优化了Controller的action(Servlet),Spring框架用来整合SpringMVC和MybatisSpringMVC的优点:轻......
  • SpringBoot - [02] 第一个SpringBoot程序
     一、引入依赖<!--web依赖:tomcat,dispatcherServlet,xml--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><!--spring-boot-starter所有的s......
  • 基于SpringBoot实现企业技术员工测评考试管理系统演示【附项目源码+论文说明】
    基于SpringBoot实现企业技术员工测评考试管理系统演示摘要社会的发展和科学技术的进步,互联网技术越来越受欢迎。网络计算机的生活方式逐渐受到广大人民群众的喜爱,也逐渐进入了每个用户的使用。互联网具有便利性,速度快,效率高,成本低等优点。因此,构建符合自己要求的操作系......
  • 基于springboot实现网页时装购物系统演示【附项目源码+论文说明】
    基于springboot实现网页时装购物系统演示摘要随着科学技术的飞速发展,社会的方方面面、各行各业都在努力与现代的先进技术接轨,通过科技手段来提高自身的优势,时装购物系统当然也不能排除在外。时装购物系统是以实际运用为开发背景,运用软件工程原理和开发方法,采用springboot......
  • 基于springcloud实现鲜花订购网微服务演示【附项目源码】
    基于springcloud实现鲜花订购网微服务演示JAVA简介Java主要采用CORBA技术和安全模型,可以在互联网应用的数据保护。它还提供了对EJB(EnterpriseJavaBeans)的全面支持,javaservletAPI,JSP(javaserverpages),和XML技术。Java是一种计算机编程语言,具有封装、继承和多态性三个......
  • 【SpringBoot】自定义工具类实现Excel数据新建表存入MySQL数据库
    ......
  • Java基础语法五
    面向对象基础(1)对象是什么(2)对象在计算机中的执行原理每次newStudent(),就是在堆内存中开辟一块内存区域代表一个对象新对象s1变量里面记住的是新对象的堆内存地址,也就是说s1是一个引用变量注:调用每个对象的变量 是 调用每个对象在堆内存存储的变量值        ......
  • Spring揭秘:Aware接口应用场景及实现原理!
    内容概要Aware接口赋予了Bean更多自感知的能力,通过实现不同的Aware接口,Bean可以轻松地获取到Spring容器中的其他资源引用,像ApplicationContext、BeanFactory等。这样不仅增强了Bean的功能,还提高了代码的可维护性和扩展性,从而让Spring的IoC容器变得更加强大和灵活。核心......
  • Spring揭秘:BeanDefinition接口应用场景及实现原理!
    BeanDefinition接口灵活性高,能够描述Bean的全方位信息,使得Spring容器可以智能地进行依赖注入和生命周期管理。同时,它支持多种配置方式,简化了Bean的声明和配置过程,提高了开发效率和可维护性。技术应用场景BeanDefinition接口定义了一个Bean的元数据,它包含了用于创建Bean对......