基于Spring Boot的秒杀系统设计与实现

news2024/7/2 3:50:18

末尾获取源码
开发语言:Java
Java开发工具:JDK1.8
后端框架:SpringBoot
前端:Vue
数据库:MySQL5.7和Navicat管理工具结合
服务器:Tomcat8.5
开发软件:IDEA / Eclipse
是否Maven项目:是


目录

一、项目简介

二、系统功能

三、系统项目截图

3.1前台首页

3.2后台管理

四、核心代码

4.1登录相关

4.2文件上传

4.3封装


一、项目简介

社会发展日新月异,用计算机应用实现数据管理功能已经算是很完善的了,但是随着移动互联网的到来,处理信息不再受制于地理位置的限制,处理信息及时高效,备受人们的喜爱。本次开发一套基于Spring Boot的秒杀系统,管理员功能有个人中心,用户管理,商品类型管理,商品信息管理,订单管理,系统管理。用户可以注册登录,查看商品信息,对秒杀商品购买,秒杀活动结束的商品不可以购买,可以可以查看订单。基于Spring Boot的秒杀系统服务端用Java开发,用Spring Boot框架开发的网站后台,数据库用到了MySQL数据库作为数据的存储。这样就让用户用着方便快捷,都通过同一个后台进行业务处理,而后台又可以根据并发量做好部署,用硬件和软件进行协作,满足于数据的交互式处理,让用户的数据存储更安全,得到数据更方便。


二、系统功能

基于Spring Boot的秒杀系统设计与实现主要包括两大功能模块,即用户功能模块和管理员功能模块。

(1)管理员模块:系统中的核心用户是管理员,管理员登录后,通过管理员来管理后台系统。主要功能有:个人中心,用户管理,商品类型管理,商品信息管理,订单管理,系统管理。

(2)用户:用户可以注册登录,查看商品信息,对秒杀商品购买,秒杀活动结束的商品不可以购买,可以可以查看订单。



三、系统项目截图

3.1前台首页

用户可以查看商品信息,可以购买和加入购物车,也可以评论和收藏。

 用户把商品加入到购物车里后可以在购物车里对商品数量更改和删除。

用户在购物车里点击确认下单后到以下界面,这个界面可以对收货地址修改,可以进行支付操作。

用户收藏过的商品信息可以在我的收藏里查看查询和删除。

3.2后台管理

管理员可以对用户信息进行添加,修改,删除,查询操作。

管理员可以对商品类型信息进行添加,修改,删除,查询操作。

管理员可以对商品信息进行添加,修改,删除,查询操作。

管理员可以查看已支付订单,可以对订单进行发货。


四、核心代码

4.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();
    }
}

4.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);
	}
	
}

4.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;
	}
}

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

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

相关文章

陌生交友发布动态圈子单聊打招呼群聊app开发

陌生交友发布动态圈子单聊打招呼群聊app开发 功能有&#xff0c;发布圈子&#xff0c;发布动态&#xff0c;查看附近的人&#xff0c;发布活动&#xff0c;实人认证&#xff0c;个人主页&#xff0c;相册查看,单聊&#xff0c;群聊。 即时通讯第三方goeasy接口。 好的&#x…

017+图解C语言中函数栈帧的创建与销毁(VS2022环境)

0.前言 您好&#xff0c;这里是limou3434的一篇个人博文&#xff0c;感兴趣的话您也可以看看我的其他文章。本次我将和您一起学习在C语言中函数栈帧的概念。 1.学习函数栈帧的意义 局部变量是怎么穿创建的&#xff1f;为什么局部变量的值是随机的函数是怎么传参的&#xff1…

满分Spring全家桶笔记:Spring+Spring Boot+Spring Cloud+Spring MVC

最近小编整理了一下一线架构师的Spring全家桶笔记&#xff1a;SpringSpring BootSpring CloudSpring MVC&#xff0c;分享给大家一起学习一下~ 01 Spring Spring是一个轻量级控制反转(IoC)和面向切面(AOP)的容器框架。Spring框架是由于软件开发的复杂性而创建的。Spring使用的…

nacos+frp穿透实现局域网调用

简介&#xff1a;首先你要有外网服务器。在外网服务器上安装frp服务端。然后在你想要调用的局域网电脑上安装frp客户端 frp下载链接 Releases fatedier/frp GitHub 外网服务器上我用的是docker安装的。你也可以直接下载并启动。这里我就不描述了。 首先我们先创建某个目录…

ESP32 ADC测量电压 arduino

ADC ADCESP32的ADC通道衰减倍数代码实现精度问题 ADC ADC&#xff08;模拟-数字转换器&#xff09;&#xff0c;首先了解模拟信号和数字信号之间的差异。模拟信号是连续的&#xff0c;可以在其范围内取无限个离散值&#xff0c;例如声音、光线等。 数字信号则是离散的&#xf…

Redis(三)常用配置解析

文章目录 度量单位引入其他配置文件启动时加载模块网路配置GENERAL 通用配置REPLICATION 主从复制相关配置安全配置AOF配置 提示&#xff1a;Redis 6.2.6版本 度量单位 注意&#xff1a;g和gb有区别&#xff0c;不区分大小写&#xff0c;1gb 1GB都是一样的。引入其他配置文件…

Qt编程基础 | 第三章-控件 | 3.3、对话框

一、QDialog 1.1、定义 对话框&#xff1a;在主窗口中操作&#xff0c;有可能触发某一个行为动作&#xff0c;会弹出一个新的对话窗口&#xff0c;解决一个临时性的会话&#xff0c;在对话窗口中执行某一个功能。QDialog可以作为自定义对话框的基类&#xff0c;同时Qt也提供了…

Hadoop部署本地模式

​ 本地模式&#xff0c;即运行在单台机器上。没有分布式的思想&#xff0c;使用的是本地文件系统。使用本地模式主要是用于对MapReduce的程序的逻辑进行调试&#xff0c;确保程序的正确性。由于在本地模式下测试和调试MapReduce程序较为方便&#xff0c;因此&#xff0c;这种模…

java实现大气质量插值图及六项污染物插值图图片导出

软件导出成果图效果 一、技术实现应用背景 大气污染是当今世界面临的一个严重问题。它不仅对人类健康造成了危害&#xff0c;还对环境和生态系统产生了负面影响。在许多地区&#xff0c;大气污染已经成为了日常生活中不可忽视的问题。 虽然大气污染的问题是复杂的&#xff0c;…

关于如何使用 python 下载CSV格式数据

本章节内容节自《python 编程从入门到实践》第十六章&#xff0c;我们将从网络上下载数据&#xff0c;并对数据进行可视化。就可以对其进行分析甚至观察其规律和关联。 学习目标 我们将访问并可视化以下两种常见格式存储的数据&#xff1a; CSV 使用 Python 模块 CSV 来处理以…

测试2年,26岁大龄程序员面试13家公司,拿下25K,差点被面试官KO了···

前言 我大概面试了13家公司&#xff0c;简历包装的是两年半测试经验&#xff0c;因为我的年纪已经是26岁&#xff0c;所以必须进行包装&#xff0c;这也并不是我想欺骗别人&#xff0c;而是现在无论干什么工作都需要有工作经验的&#xff0c;就连找个销售都要有工作经验的&…

Vue绑定class样式与style样式

1&#xff0c;回顾HTML的class属性 答&#xff1a;任何一个HTML标签都能够具有class属性&#xff0c;这个属性可能只有一个值&#xff0c;如class"happs"&#xff0c;也有可能存在多个属性值&#xff0c;如class"happs good blue"&#xff0c;js的原生DOM针…

STM32开发踩坑——芯片写保护解除

成立这个专栏的目的是&#xff0c;记录自己嵌入式开发遇到的问题&#xff0c;与成功的解决方法&#xff0c;方便自己回顾。 具体参考链接&#xff1a;STM32的Flash写了保护怎么办&#xff1f; 解决方法&#xff1a;在STLink连接目标板的情况下打开程序烧写软件ST-Link Utilit…

低代码开发迎来设备管理新时代:智能制造加速升级

随着智能制造时代的到来&#xff0c;制造业正在经历一场前所未有的变革。在这场变革中&#xff0c;设备管理平台和低代码开发已经成为了制造业的不二利器&#xff0c;帮助企业实现数字化转型&#xff0c;提高生产效率&#xff0c;降低成本&#xff0c;增强竞争力。 一、设备管…

OptaPlanner 中的hello world项目实战

实际操作步骤&#xff1a; 1.代码下载 下载下来的文件目录 2.使用编辑器打开hello-world项目 3.进行配置 配置JDK &#xff0c;File——》Settings File——》Project Structure 配置maven 说明&#xff1a;不用下载新的maven&#xff0c;用工具自带的&#xff0c;需要将sett…

旋翼无人机常用仿真工具

四旋翼常用仿真工具 rviz&#xff1a; 简单的质点&#xff08;也可以加上动力学姿态&#xff09;&#xff0c;用urdf模型在rviz中显示无人机和飞行轨迹、地图等。配合ROS代码使用&#xff0c;轻量化适合多机。典型的比如浙大ego-planner的仿真&#xff1a; https://github.c…

screen 的介绍及用法

screen 是什么 screen 是一种类似于终端模拟器的程序&#xff0c;允许你在一个终端窗口中创建和使用多个会话。这对于同时运行多个命令或任务非常有用&#xff0c;这样你就可以轻松地在它们之间切换&#xff0c;而不必依赖于多个终端窗口。此外&#xff0c;如果在ssh会话中运行…

HDMI之带宽计算

基本概念 像素时钟 英文 A pixel clock, also known as a dot clock, is a term commonly used in computer graphics and video display systems. It refers to the frequency at which pixels are displayed on a screen or monitor. The pixel clock determines the speed…

VMware是什么?VMware虚拟机最新安装教程

VMware Workstation是一款虚拟机软件&#xff0c;允许用户将Linux、Windows等多个操作系统作为虚拟机在单台PC上运行; 用户可以在虚拟机上重现服务器、桌面和平板电脑环境&#xff0c;无需重新启动即可跨不同操作系统同时运行应用。 通过对个人笔记本(PC)硬件资源的虚拟&#…

【zmq】REQ REP 模式

[c代码(https://github.com/dongyusheng/csdn-code/tree/master/ZeroMQ)zguide 官方有c++发布订阅:可以使用信封 发布订阅可以让消息一直流动请求应答是双向的,但是必须请求 应答 请求 应答 循环。简单的请求应答 requester 作为客户端以tcp连接到 reponderrequester zmq_sen…