基于SpringBoot的图书电子商务网站设计与实现

news2024/10/5 12:16:45

目录

前言

 一、技术栈

二、系统功能介绍

管理员功能实现

用户管理

图书分类管理

图书信息管理

订单管理

用户功能实现

图书信息

购物车

确认下单

我的收藏

三、核心代码

1、登录模块

 2、文件上传模块

3、代码封装


前言

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

 一、技术栈

末尾获取源码
SpringBoot+Vue+JS+ jQuery+Ajax...

二、系统功能介绍

管理员功能实现

用户管理

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

图书分类管理

管理员可以对图书分类信息进行添加,修改,删除,查询操作。

 

图书信息管理

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

 

订单管理

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

 

用户功能实现

图书信息

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

 

购物车

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

 

确认下单

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

 

我的收藏

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

 

三、核心代码

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

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

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

相关文章

【蓝桥杯选拔赛真题05】C++超级素数 青少年组蓝桥杯C++选拔赛真题 STEMA比赛真题解析

目录 C/C++超级素数 一、题目要求 1、编程实现 2、输入输出 二、算法分析 <

BAT035.【工作常用批处理专栏】批处理功能说明及下载

引言:本文主要提供本专栏中练习的批处理功能进行说明和下载。 一、本专栏练习的批处理下载地址 链接:https://pan.baidu.com/s/1L_V-_LojpbfFcUFbvBK1_A 提取码:vady 二、本专栏练习的批处理汇总如下 【工作常用批处理专栏】批处理目录树: │ BAT001.CMD命令速查手册.h…

脚本木马编写

PHP小马编写 小马用waf扫描&#xff0c;没扫描出来有风险。 小马过waf之后用echo $_SERVER[DOCUMENT_ROOT]获得当前运行脚本所在的文档根目录。&#xff0c;然后在上传大马工具。 $_SERVER&#xff0c;参考&#xff1a;PHP $_SERVER详解 小马编写二次加密 现在是可以被安全…

uniapp中APP端使用echarts用formatter设置y轴保留2位小数点不生效

uniapp使用echarts&#xff0c;在内置浏览器中&#xff0c;设置保留2位小数能正常显示&#xff08;代码如下&#xff09;&#xff0c;但是在APP端这个设置不起作用。 yAxis: {type: value,axisLabel: {formatter: function (val) {return val.toFixed(2); //y轴始终保留小数点…

Flask_Login使用与源码解读

一、前言 用户登录后&#xff0c;验证状态需要记录在会话中&#xff0c;这样浏览不同页面时才能记住这个状态&#xff0c;Flask_Login是Flask的扩展&#xff0c;专门用于管理用户身份验证系统中的验证状态。 注&#xff1a;Flask是一个微框架&#xff0c;仅提供包含基本服务的…

redis-集群切片

切片集群 我曾遇到过这么一个需求&#xff1a;要用 Redis 保存 5000 万个键值对&#xff0c;每个键值对大约是 512B&#xff0c;为了能快速部署并对外提供服务&#xff0c;我们采用云主机来运行 Redis 实例&#xff0c;那么&#xff0c;该如何选择云主机的内存容量呢&#xff…

【设计模式】第10节:结构型模式之“组合模式”

一、简介 组合模式&#xff1a;将一组对象组织成树形结构&#xff0c;将单个对象和组合对象都看做树中的节点&#xff0c;以统一处理逻辑&#xff0c;并且它利用树形结构的特点&#xff0c;递归地处理每个子树&#xff0c;依次简化代码实现。使用组合模式的前提在于&#xff0…

【数据结构与算法】JavaScript实现集合与字典

文章目录 一、集合结构1.1.简介1.2.代码实现1.3.集合间的操作 二、字典结构2.1.简介2.2.封装字典 一、集合结构 1.1.简介 集合比较常见的实现方式是哈希表&#xff0c;这里使用JavaScript的Object类进行封装。 集合通常是由一组无序的、不能重复的元素构成。 数学中常指的集…

记录linux运行服务提示报错/bin/java: 没有那个文件或目录

描述&#xff1a;在执行jar启动命令时候提示 没有/bin/java 这个文件或者目录&#xff1b;然后我vi /usr/bin/java&#xff0c;是存在该文件的&#xff1b;那到底是什么问题呢&#xff0c;该不是没有创建软连接吧&#xff1f; 1、执行下述命令先测试下软链接是否有创建 ln -s …

SpringCloud微服务保护方案解读

目录 服务雪崩定义 问题的产生 示例 雪崩产生的几种场景 解决方案 熔断模式 隔离模式&#xff08;仓壁模式 &#xff09; 限流模式 超时处理 总结 服务保护技术对比 服务雪崩定义 我们都知道在微服务中&#xff0c;服务间调用关系错综复杂&#xff0c;一个微服务…

2023年中国特种运输现状及市场格局分析[图]

特种运输是使用特殊车辆、方案&#xff0c;将特种货物转移至需求地的过程。相对于常规货物&#xff0c;特种货物在本身特性&#xff08;危险品、鲜活货物&#xff09;、价值&#xff08;贵重物品&#xff09;、体积&#xff08;超大货物&#xff09;、重量&#xff08;超重货物…

【AD9361 数字接口CMOS LVDSSPI】C 并行数据 LVDS

接上一部分&#xff0c;AD9361 数字接口CMOS &LVDS&SPI 目录 一、LVDS模式数据路径和时钟信号LVDS模式数据通路信号[1] DATA_CLK[2] FB_CLK[3] Rx_FRAME[4] Rx_D[5&#xff1a;0][5] Tx_FRAME[6]Tx_D[5&#xff1a;0][7] ENABLE[8] TXNRX系列 二、LVDS最大时钟速率和信…

JavaScript对象与原型:揭示编程世界的奥秘

目录 对象&#xff1a;万物皆对象 原型&#xff1a;共享和继承的基石 继承与原型链 对象与原型的关系 对象的创建 原型与原型链 原型继承 总结 在JavaScript中&#xff0c;对象是非常重要的概念之一。它们允许我们以一种结构化的方式存储和组织数据&#xff0c;并提供了…

【ROS教程demo】用C++创建一个ROS节点,发布指令使得小海龟做圆周运动

ROS创建节点发布命令使得小海龟做圆周运动 1.任务需求2.任务分析2.1发布方topic和msg2.2接收方topic和msg2.3目标明确!3.创建ROS节点3.1创建发布方节点pub_pose3.2创建订阅方节点sub_pose1.任务需求 创建一个节点,在其中实现一个订阅者和一个发布者,完成以下功能: 发布者:…

打造中国汽车出海新名片,比亚迪亮相东京车展

作为全球知名的国际车展&#xff0c;东京车展向来都被业界人士誉为“亚洲汽车风向标”。2023年10月25日&#xff0c;第47届东京车展&#xff08;自2023年更名为“日本移动出行展”&#xff09;在东京国际展览中心如期揭幕。 作为中国车企的代表品牌&#xff0c;比亚迪携海豹、海…

40基于MATLAB,使用模板匹配法实现车牌的识别。

基于MATLAB&#xff0c;使用模板匹配法实现车牌的识别。具体包括将原图灰度化&#xff0c;边缘检测&#xff0c;腐蚀操作&#xff0c;车牌区域定位&#xff0c;车牌区域矫正&#xff0c;二值化&#xff0c;均值滤波&#xff0c;切割&#xff0c;字符匹配&#xff0c;最终显示车…

【数据库】Python脚本实现数据库批量插入事务

背景介绍 在工作中可能会遇到需要批量插入的场景, 而批量插入的过程具有耗时长的特点, 再此过程很容易出现程序崩溃的情况.为了解决插入大量数据插入后崩溃导致已插入数据无法清理及未插入数据无法筛出的问题, 需要编写一个脚本记录已插入和未插入的数据, 并可以根据记录的数据…

阿里云服务linux系统CentOs8.5安装/卸载nginx1.15.9

说明&#xff1a;尝试使用CentOs8.5安装nginx1.9.9失败&#xff0c;make的时候报错了&#xff0c;后面降低版本为CentOs7.5安装成功了&#xff0c;参考文章:【精选】centos7安装nginx-1.9.9_linx centos nginx 1.9.9版本 nginx error log file: "/-CSDN博客 一、安装ngin…

Animator中Has Exit Time,融合时间

写这篇文章的原因是&#xff0c;发现有时候SetTrigger后动画没有切换&#xff0c;做实验找到了原因。 一、勾选了Has Exit Time 动画一定会在设定的时间才可能会切换到下个动画片段。 NormalAttack1-->NormalAttack2,结束时间设置0.5 NormalAttack1-->NormalAttack3,结…

什么是Immutable.js?它的作用是什么?

聚沙成塔每天进步一点点 ⭐ 专栏简介 前端入门之旅&#xff1a;探索Web开发的奇妙世界 欢迎来到前端入门之旅&#xff01;感兴趣的可以订阅本专栏哦&#xff01;这个专栏是为那些对Web开发感兴趣、刚刚踏入前端领域的朋友们量身打造的。无论你是完全的新手还是有一些基础的开发…