基于springboot家具商城系统

news2024/9/29 3:31:37

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


前言

基于springboot家具商城系统有两大角色:

用户:首页、家具信息、公告信息、个人中心、后台管理、购物车。

管理员:个人中心、用户管理、家具类型管理、家具信息管理、系统管理、订单管理。

前台首页

 在前台首页我们可以看到有首页、家具信息、公告信息、个人中心、后台管理、购物车。

 在家具商城系统我们可以看到家具信息推荐,用户可以选择自己喜欢的家具加入购物车或者选择下单。

 选择好自己喜欢的家具点击会跳转到家具信息的相关页面。

 在家具信息中可以查看家具的类型或者搜索。

 在公告信息页面,用户可以查看管理员发布的信息。

 未登录的,系统会跳转到登录页面或者没有账号的用户可以点击注册进行注册然后在登录。

 登录后的用户可以在个人中心查看自己的信息并且可以修改。

管理员功能

 管理员后台登录页面。

 管理员登录后可以看到有个人中心、用户管理、家具类型管理、家具信息管理、系统管理、订单管理。

用户管理页面。

家具类型管理页面。

家具信息管理页面


登录模块核心代码


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

文件上传核心代码

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

 封装代码

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/545978.html

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

相关文章

js数组排序的两种方法

1. 冒泡排序 原理&#xff1a;一次比较两个相邻的数&#xff0c;如果不符合规则互换位置&#xff0c;一次比较就能够将最大或最小的值放在数组最后一位继续对除【最后一位】之外的所有元素重复上述过程。 let arr [22,1,43,12,75,32]; for(let i 0; i < arr.length - 1;…

MySQL一条查询语句是怎么执行的?MySQL 的架构是什么样子?

先谈谈MySQL的架构&#xff0c;这样自然就搞清楚一条语句是怎么执行的了 首先&#xff0c;MySQL分为客户端&#xff0c;服务端&#xff0c;存储引擎 客户端&#xff1a; ● Java程序啊&#xff0c;可视化连接工具 Navicat啊等等&#xff0c;就是客户端&#xff1b; 服务端&…

Vivado 下 IP核 之ROM 读写

目录 Vivado 下 IP核 之ROM 读写 1、实验简介 2、ROM IP 核简介 3、ROM IP 核配置 3.1、创建 ROM 初始化文件 3.2、单端口 ROM 的配置 3.3、双端口 ROM 的配置 3.4、ROM IP 核的调用 &#xff08;1&#xff09;ROM 顶层模块代码 &#xff08;2&#xff09;ROM IP 核仿…

lua-5.3.6源码安装

参考博客有https://blog.csdn.net/m0_53157173/article/details/124653430和http://blog.chinaunix.net/uid-14824714-id-3125340.html。 https://www.lua.org/download.html下载网址。点击当前网址中的“download”超链接可以下载以前的版本。 cat /etc/redhat-release看一下…

408考研计算机之计算机组成与设计——计算机层次系统概述2

目录 一、 冯诺依曼机基本思想 二、计算机的功能部件 1、输出输入设备 2、存储器 3、运算器 4、控制器​​​​​​​ 三、指令执行过程的描述 一、 冯诺依曼机基本思想 首先&#xff0c;第一个问题&#xff0c;冯诺依曼是谁&#xff1f;小编第一次知道这个名字&#xff…

Qt将十二位整形十进制转换成十六进制,在转为ascii字符,并下发串口。在接受端完整还原这个十二位的十进制数。

可以按照以下步骤进行操作&#xff1a; 将十进制数123456789012转换成十六进制字符串&#xff1a; QString hexString QString("%1").arg(123456789012ull, 0, 16);其中&#xff0c;%1表示替换第1个参数&#xff0c;0表示输出的最小位数为0&#xff0c;16表示输出…

Capturing Omni-Range Context for Omnidirectional Segmentation总结笔记

Capturing Omni-Range Context for Omnidirectional Segmentation&#xff08;捕获全范围上下文进行全方位分割&#xff09; 目录 一、论文出发点 二、论文核心思想 三、论文工作中主要问题 四、方法论 五、实验 六、结论 一、论文出发点 大多数用于分析城市环境的分割…

springboot+swagger项目中,controller引入@NotEmpty等校验注解的问题

springboot项目 springbootswagger项目中&#xff0c;controller层如果使用对基本数据类型使用 NotEmpty Length 等校验注解&#xff0c;controller会获取不到值&#xff0c;加了RequestBody后可以获取到了&#xff0c;但是前端传值content-type必须是text/plain。所以建议con…

考研数据结构--树和二叉树(2)

文章目录 二叉树的遍历前序遍历中序遍历后序遍历层次遍历 不用栈的二叉树中序遍历算法Morris代码分析 二叉树的构造概述如何完成二叉树的构造**回顾****思考**各种遍历序列提供的信息二叉树遍历性质性质1性质2 线索化二叉树引入定义构造 堆堆的定义堆的性质堆的建立堆的元素插入…

GPT1解读:Improving Language Understanding by Generative Pre-Training

自然语言处理NLP是当代人工智能的关键领域&#xff0c;包含文本识别、智能问答等多个方向任务&#xff0c;通过监督学习方式一般需要大量带标签数据&#xff0c;而对某些特定任务&#xff0c;获取带标签数据成本非常高。GPT通过大量的未标记文本数据来学习一个通用预训练&#…

ZiKiT DICOM 存档(PACS)模态服务器 Crack

ZiKiT结合了DICOM存档&#xff08;PACS&#xff09;&#xff0c;模态工作列表服务器和HL7消息代理&#xff0c;它们共享相同的数据库并相互通信。 最新版本 – ZiKiT 2020 ZiKiT 提供动态映射规则和消息结构定义&#xff0c;同时保持合规性并遵守标准。该套件使非程序员能够在…

电动力学:电偶极辐射场

电磁辐射的产生条件 存在时变源&#xff08;时变的电荷源、时变的电流源&#xff0c;或时变的电磁场&#xff09;时变源的频率应足够高&#xff08;辐射系统的尺寸大小和电磁波波长差不多时&#xff0c;才有可能产生明显的辐射效应&#xff09;波源电路必须开放&#xff08;源电…

Android 如何获取有效的DeviceId

目录 前言官方唯一标识符建议使用广告 ID使用实例 ID 和 GUID不要使用 MAC 地址标识符特性常见用例和适用的标识符 解决方案DeviceIdANDROID_IDMac地址UUID补充 总结 前言 从 Android 10 开始&#xff0c;应用必须具有 READ_PRIVILEGED_PHONE_STATE 特许权限才能访问设备的不可…

新手建站:腾讯云轻量服务器安装宝塔镜像和使用方法

腾讯云轻量应用服务器宝塔面板怎么用&#xff1f;轻量应用服务器如何安装宝塔面板&#xff1f;在镜像中选择宝塔Linux面板腾讯云专享版&#xff0c;在轻量服务器防火墙中开启8888端口号&#xff0c;然后远程连接到轻量服务器执行宝塔面板账号密码查询命令&#xff0c;最后登录和…

Java内存模型介绍

Java作为一种面向对象的&#xff0c;跨平台语言&#xff0c;其对象、内存等一直是比较难的知识点。而且很多概念的名称看起来又那么相似&#xff0c;很多人会傻傻分不清楚。比如本文要讨论的JVM内存结构、Java内存模型和Java对象模型&#xff0c;这就是三个截然不同的概念&…

系列四、vue3 初始化项目(图形化界面方式)

一、启动UI界面 vue ui 二、创建项目 2.1、在此创建项目 2.2、创建新项目-详情配置 2.3、创建新项目-预设 2.4、创建新项目-功能 2.5、创建新项目-配置 2.6、运行项目 任务》serve》运行》启动app 2.7、首页 三、安装element-plus 3.1、步骤 ①、运行 vue ui 命令&#…

【C++初阶】想要编译器为你干活吗?来试试模板吧(模板初阶)

一.泛型编程 引入 我们之前都写过交换函数Swap&#xff0c;例如这样的&#xff1a; //交换两个整型 void Swap(int*x1, int *x2) {int tmp *x1;*x1 *x2;*x2 tmp;} 如果要交换其它的类型该怎么办呢&#xff1f; 那只能当个CV工程师了&#xff0c;然后再修修改改&#xff0c;…

java枚举enum

目录 一、概念二、声明枚举三、枚举类四、为枚举添加方法五、EnumMap 与 EnumSet 一、概念 枚举是一个被命名的整型常数的集合&#xff0c;用于声明一组带标识符的常数。枚举在曰常生活中很常见&#xff0c;例如一个人的性别只能是“男”或者“女”&#xff0c;一周的星期只能…

CAN总线通讯协议学习

s目录 CAN&#xff08;controller Area Network) 控制器局域网 CAN通讯 CAN总线的数据帧 解析 CAN&#xff08;controller Area Network) 控制器局域网 CAN总线应用最多的是汽车领域,这里的控制器在汽车领域的专业术语是ECU.(electronic control unit)电子控制单元。可以看成…

【计算机网络之HTTP篇】HTTP协议详解

目录 一、HTTP协议概念 二、HTTP 协议格式 三、HTTP请求详解 认识URL 认识HTTP方法 GET POST Host Content-Length Content-Type User-Agent (简称 UA) Referer Cookie 四、HTTP 响应详解 状态码 200 OK 404 Not Found 403 Forbidden 500 Internal Server E…