基于javaweb的SpringBoot前后端分离网上商城项目设计和实现(java+ssm+springboot+maven+vue+redis+oss)

运行环境

Java≥8、MySQL≥5.7、Node.js≥14

开发工具

后端:eclipse/idea/myeclipse/sts等均可配置运行
前端:WebStorm/VSCode/HBuilderX等均可

❗没学过node.js的不要搞前后端分离项目

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

540123042402

550123042402

560123042402

570123042402

580123042402

590123042402

000123052402

010123052402

020123052402

030123052402

050123052402

060123052402

070123052402

080123052402

090123052402

100123052402

110123052402

120123052402

130123052402

140123052402

160123052402

112024363108

基于javaweb的SpringBoot前后端分离网上商城项目设计和实现(java+ssm+springboot+maven+vue+redis+oss)

1
2
3
4
5
6
7
8
9
10

后台管理员:
1325554003@qq.com/123456

前台用户:
user1@qq.com/123456

1 启动后端:StartApplication
2 启动前端:npm run dev

主要功能实现:

用户登录、注册、商城浏览、购买、订单、购物车、退货、用户、个人中心、修改密码、角色等管理

前端主页面:商品关键字搜索和分类搜索功能以及首页轮播图配置展示

首页个人中心主要功能:密码修改、订单、购物车、商品详情模块、可以购买、加入购物车

购买时需要填写用户手机号和收获地址等信息

后台管理员主要对商品数据进行管理、分类管理、订单管理以及用户管理

商品列表数据管理、后台添加商品信息、商品基础数据的维护管理、商品订单详情管理:根据关键字查询以及查看每一个订单的详情信息

首页轮播图配置展示、用户角色和权限管理控制

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
    }
}

@RequestMapping(value = "/allow/sendHtmlRegister")
public CommonResult sendRegisterInfo(String sendTo, String pwd, String name) {
try {
Map<String, Object> data = new HashMap<>();
data.put("account", sendTo);
data.put("password", pwd);
data.put("name", name);
data.put("year", Calendar.getInstance().get(Calendar.YEAR));
mailService.sendTemplateMail(sendTo, "注册成功", "register", data);
return CommonResult.success("注册信息发送成功");
} catch (Exception e) {
return CommonResult.error("注册信息发送失败");
}
}

@RequestMapping(value = "/allow/sendHtmlRole")
public CommonResult sendRoleInfo(String sendTo, String userName, String roleInfo) {
try {
Map<String, Object> data = new HashMap<>();
data.put("userName", userName);
data.put("roleInfo", roleInfo);
data.put("year", Calendar.getInstance().get(Calendar.YEAR));
mailService.sendTemplateMail(sendTo, "权限管理", "role", data);
return CommonResult.success("授权信息发送成功");
} catch (Exception e) {
return CommonResult.error("授权信息发送失败");
}
}

@RequestMapping(value = "/allow/sendHtmlResetPwd")
public CommonResult sendResetPwd(String sendTo, String pwd) {
try {
Map<String, Object> data = new HashMap<>();
data.put("password", pwd);
data.put("year", Calendar.getInstance().get(Calendar.YEAR));
mailService.sendTemplateMail(sendTo, "重置密码", "resetpwd", data);
return CommonResult.success("新密码信息发送成功");
} catch (Exception e) {
return CommonResult.error("新密码信息发送失败");
}
}


/**
* 发送一个邮箱附件
*
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
    Integer count = orderService.selectCount();
if(count!=null){
return CommonResult.success("订单数量查询成功",count);
}else{
return CommonResult.error("订单数量查询失败");
}
}


@RequestMapping(value = "/order/add")
private CommonResult addOrder(Order order) {
if(order!=null){
if(order.getProductNo().contains("Vip")){
if(orderService.insertData(order)){
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
Product product = productService.selectByKey(order.getProductNo());
Integer productStock = product.getProductStock();
Integer payAmount = order.getPayAmount();
boolean isOk =productStock >= payAmount;
if(isOk){
Product newProduct = new Product();
newProduct.setProductId(product.getProductId());
int newStock = productStock - payAmount;
newProduct.setProductStock(newStock);
newProduct.setIsStockOut(newStock<product.getLowestStock());
// 如果库存小于等于0,自动下架
newProduct.setIsSale(newStock>0);
if(productService.updateById(newProduct)){
if(orderService.insertData(order)){
redisTemplate.opsForValue().set(order.getOrderNo(),order.getOrderNo(),24, TimeUnit.HOURS);
return CommonResult.success("创建订单成功",order);
}else{
return CommonResult.error("创建订单失败");
}
}else{
return CommonResult.error("创建订单失败");
}
}else{
return CommonResult.error("商品库存不足");
}
}
}else{
return CommonResult.error("订单数据不完整");
}
}


@RequestMapping(value = "/order/cartOrder")
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    }else{
return CommonResult.error("查询失败");
}

}

//通过用户帐号去查询用户的id
@RequestMapping(value = "/user/findIdByKey")
private CommonResult findIdByKey(String key) {
Integer id = userService.selectIdByKey(key);
if(id!=null){
if(id!=0){
return CommonResult.success("查询成功","id: "+id);
}else{
return CommonResult.error("未查询到");
}
}else{
return CommonResult.error("查询失败");
}
}

//删除用户
@RequestMapping(value = "/user/delete")
private CommonResult delete(Integer userId) {
if(userService.deleteById(userId)){
return CommonResult.success("删除成功",userId);
}else{
return CommonResult.error("删除失败");
}
}

@RequestMapping(value = "/user/author")
private CommonResult author(Integer userId,@RequestParam List<Integer> roleId) {
System.out.println(userId);
System.out.println(roleId);
if(userId!=null && roleId!=null && roleId.size()!=0){
if(userRoleService.deleteById(userId)){
UserRole userRole = new UserRole();
userRole.setUserId(userId);
for (Integer id : roleId) {
userRole.setRoleId(id);
userRoleService.insertData(userRole);
}
}
return CommonResult.success("授权成功");
}else{
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
@RestController
@CrossOrigin
public class OperateController {
private final Logger logger = LoggerFactory.getLogger(this.getClass());
final RoleService roleService;
final UserService userService;
final UserRoleService userRoleService;
public OperateController(UserService userService, RoleService roleService, UserRoleService userRoleService) {
this.userService = userService;
this.roleService = roleService;
this.userRoleService = userRoleService;
}

//未登录时,将被转发到此请求上
@RequestMapping("/notLogin")
private CommonResult toLogin(){
return new CommonResult(401,"请登录!");
}

/**
* 登录操作
* @param username 用户登录的帐号
* @param password 用户登录的密码
* @param rememberMe shiro框架的 记住我 功能
*/
@RequestMapping(value = "/login",produces = {"application/json;charset=UTF-8"})
private CommonResult doLogin(String username,String password,boolean rememberMe) {
try {
if (username == null) {
throw new AuthenticationException();
}
if (password == null) {
throw new IncorrectCredentialsException();
}
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken(username, password, rememberMe);
if (subject.isAuthenticated())
return CommonResult.error("已登录");
subject.login(token);
Map<String, Object> info = new HashMap<>();
String authorization = (String) subject.getSession().getId();
User user;
if (username.contains("@")) {
//包含@符号,代表用户通过邮箱帐号登录
user = userService.selectByKey(username);
} else {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
        String filePath = "F:\\IDEA\\JAVA_Program\\Springboot-Mall\\src\\main\\resources\\static\\1.zip";
mailService.sendAttachmentsMail(sendTo, "文件操作", content, filePath);
return "发送成功!";
} catch (Exception e) {
e.printStackTrace();
return "发送邮件时发生异常,稍后请重新发送!";
}
}


/**
* 验证输入的验证码是否正确
*
* @param key 验证的依据
* @param code 验证码
*/
@RequestMapping(value = "/allow/checkCode")
public CommonResult checkCode(String key, String code) {
String codeK = redisTemplate.opsForValue().get(key);
if (codeK == null) {
return CommonResult.error("验证码不存在或已过期,请重新发送!");
}
if (codeK.equals(code)) {
redisTemplate.delete(key);
return CommonResult.success("验证码成功!", true);
} else {
return CommonResult.success("验证码错误!", false);
}
}

/**
* 用于绑定手机号操作,发送验证码
*
* @param phone 发送的手机号
*/
@RequestMapping(value = "/util/smsCode")
public CommonResult aliYunSmsCode(String phone) {
String code = redisTemplate.opsForValue().get(phone);
if (!StringUtils.isEmpty(code)) {
return CommonResult.error(phone + "的验证码还未过期!");
}
//生成验证码并存储到redis中
code = MyUtils.getCode(6);
boolean isSend = aliYunSmsService.sendSms(phone, code);
if (isSend) {
redisTemplate.opsForValue().set(phone, code, 10, TimeUnit.MINUTES);
return CommonResult.success("验证码已发送,网络有延迟请稍等~");
} else {
return CommonResult.error("验证码发送失败,请稍后重试~");
}


项目链接:
https://javayms.github.io?id=481222052008200vq
https://javayms.pages.dev?id=481222052008200vq