云计算百科
云计算领域专业知识百科平台

分享一套锋哥原创的优质SpringBoot4+Vue3在线商城购物系统(优质版)

大家好,我是锋哥,分享一套锋哥原创的优质SpringBoot4+Vue3在线商城购物系统(优质版)。

项目介绍

本系统采用前后端分离的架构模式,后端基于Spring Boot 3.2框架进行开发,使用MyBatis作为持久层框架,MySQL 8.0作为数据库存储,JWT实现无状态认证机制;前端采用Vue 3框架,结合Element Plus组件库构建管理后台界面,使用Thymeleaf模板引擎渲染用户端页面。系统主要包含两大模块:用户端和管理端。用户端实现了用户注册登录、商品浏览搜索、购物车管理、订单管理、收货地址管理、商品评价等核心功能;管理端实现了仪表盘数据统计、商品管理、订单管理、用户管理、分类管理、轮播图管理、评价管理等运营功能。
 

源码下载

链接:https://pan.baidu.com/s/1OBc94Zph0woYvp1HBJjTvg?pwd=1234
提取码:1234

系统展示

核心代码

package com.java1234.controller.admin;

import com.java1234.entity.Admin;
import com.java1234.service.AdminService;
import com.java1234.util.JwtUtil;
import com.java1234.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import jakarta.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
* 管理员认证控制器
* 处理管理员登录和信息获取
*/
@RestController
@RequestMapping("/api/admin")
public class AdminAuthController {

@Autowired
private AdminService adminService;

@Autowired
private JwtUtil jwtUtil;

/**
* 管理员登录
* @param params 包含 username 和 password
* @return 登录成功返回 token 和管理员信息
*/
@PostMapping("/login")
public Result<?> login(@RequestBody Map<String, String> params) {
String username = params.get("username");
String password = params.get("password");
if (username == null || password == null) {
return Result.error("用户名和密码不能为空");
}
Admin admin = adminService.login(username, password);
if (admin == null) {
return Result.error("用户名或密码错误");
}
String token = jwtUtil.generateToken(admin.getId(), admin.getRole());
Map<String, Object> data = new HashMap<>();
data.put("token", token);
Map<String, Object> adminInfo = new HashMap<>();
adminInfo.put("id", admin.getId());
adminInfo.put("username", admin.getUsername());
adminInfo.put("avatar", admin.getAvatar());
adminInfo.put("role", admin.getRole());
data.put("admin", adminInfo);
return Result.success(data);
}

/**
* 获取管理员信息
*/
@GetMapping("/profile")
public Result<?> getProfile(HttpServletRequest request) {
Integer adminId = (Integer) request.getAttribute("adminId");
Admin admin = adminService.findById(adminId);
if (admin == null) {
return Result.error("管理员不存在");
}
Map<String, Object> data = new HashMap<>();
data.put("id", admin.getId());
data.put("username", admin.getUsername());
data.put("avatar", admin.getAvatar());
data.put("role", admin.getRole());
return Result.success(data);
}
}

赞(0)
未经允许不得转载:网硕互联帮助中心 » 分享一套锋哥原创的优质SpringBoot4+Vue3在线商城购物系统(优质版)
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!