基于javaweb的SpringBoot手机商城系统(java+springboot+maven+ssm+html+layui+thymeleaf+mysql)

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

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

功能说明

001424150701

011424150701

511424140701

531424140701

541424140701

551424140701

561424140701

571424140701

581424140701

591424140701

基于javaweb的SpringBoot手机商城系统(java+springboot+maven+ssm+html+layui+thymeleaf+mysql)

1
2
3
4
5
6
管理员
13500000000 123456

用户
13600000001 123456
13600000002 123456

项目介绍

基于SpringBoot手机商城 有前台和后台 用户可以登录注册 收藏商品 购物车 结算商品 收货地址管理等 管理员则可以对用户,商品,订单进行管理操作

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 4.数据库:MySql 5.7/8.0版本均可; 5.是否Maven项目:是;

技术栈

后端:SpringBoot(Spring+SpringMVC+Mybatis)

前端: HTML+Layui+thymeleaf

使用说明

项目运行: 1. 使用Navicat或者其它工具,在mysql中创建对应sql文件名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.yml配置文件中的数据库配置改为自己的配置;

商城首页展示:

商品下单购物车:

 登录展示:

 提交订单展示:

 我的订单展示:

我的订单管理:

后台登录管理展示:

后台管理轮播图展示:

后台管理订单列表展示:

后台管理商品列表展示:

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
    User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(Cart::getUserId, currentUser.getId())
.eq(Cart::getGoodId, cart.getGoodId());
Cart currentCart = cartService.getOne(queryWrapper);
if (currentCart == null) {
cart.setNum(1);
cart.setUserId(currentUser.getId());
return Result.decide(cartService.save(cart));
} else {
LambdaUpdateWrapper<Cart> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper
.eq(Cart::getUserId, currentUser.getId())
.eq(Cart::getGoodId, cart.getGoodId())
.set(Cart::getNum, currentCart.getNum() + 1);
return Result.decide(cartService.update(updateWrapper));
}
}

//购物数量减少
@PostMapping("/delete")
public Result delete(Cart cart) {
User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(Cart::getUserId, currentUser.getId())
.eq(Cart::getGoodId, cart.getGoodId());
Cart currentCart = cartService.getOne(queryWrapper);
if (currentCart.getNum() <= 1) {
return Result.failure("不能再减了..");
} else {
LambdaUpdateWrapper<Cart> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper
.eq(Cart::getUserId, currentUser.getId())
.eq(Cart::getGoodId, cart.getGoodId())
.set(Cart::getNum, currentCart.getNum() - 1);
return Result.decide(cartService.update(updateWrapper));
}
}

//购物数量减少
@PostMapping("/cartDelete")
public Result cartDelete(Cart cart) {
return Result.decide(cartService.removeById(cart.getId()));
}

//获取用户购物车信息
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
            .eq(Cart::getUserId, currentUser.getId())
.eq(Cart::getGoodId, cart.getGoodId());
Cart currentCart = cartService.getOne(queryWrapper);
if (currentCart == null) {
cart.setNum(1);
cart.setUserId(currentUser.getId());
return Result.decide(cartService.save(cart));
} else {
LambdaUpdateWrapper<Cart> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper
.eq(Cart::getUserId, currentUser.getId())
.eq(Cart::getGoodId, cart.getGoodId())
.set(Cart::getNum, currentCart.getNum() + 1);
return Result.decide(cartService.update(updateWrapper));
}
}

//购物数量减少
@PostMapping("/delete")
public Result delete(Cart cart) {
User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(Cart::getUserId, currentUser.getId())
.eq(Cart::getGoodId, cart.getGoodId());
Cart currentCart = cartService.getOne(queryWrapper);
if (currentCart.getNum() <= 1) {
return Result.failure("不能再减了..");
} else {
LambdaUpdateWrapper<Cart> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper
.eq(Cart::getUserId, currentUser.getId())
.eq(Cart::getGoodId, cart.getGoodId())
.set(Cart::getNum, currentCart.getNum() - 1);
return Result.decide(cartService.update(updateWrapper));
}
}

//购物数量减少
@PostMapping("/cartDelete")
public Result cartDelete(Cart cart) {
return Result.decide(cartService.removeById(cart.getId()));
}

//获取用户购物车信息
@RequestMapping("/getAll")
public ModelAndView getAll() {
User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
LambdaQueryWrapper<Cart> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
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
/**
* <p>
* 前端控制器
* </p>
*
*/
@RestController
@RequestMapping("/address")
public class AddressController {

@Autowired
private AddressService addressService;

//添加收货地址
@PostMapping("/add")
public Result add(Address address) {
User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
//保存当前用户id
address.setUserId(currentUser.getId());
return Result.decide(addressService.save(address));
}

//删除收货地址
@PostMapping("/delete")
public Result delete(@RequestParam(value = "id") String id) {
return Result.decide(addressService.removeById(id));
}

//获得单挑地址明细
@PostMapping("/getOne")
public Result getOne(@RequestParam(value = "id") String id) {
return Result.success(addressService.getById(id));
}

//修改收货地址
@PostMapping("/update")
public Result update(Address address) {
User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
if (addressService.updateById(address)) {
if (address.getDefaulted() == 1) {
LambdaUpdateWrapper<Address> updateWrapper = new LambdaUpdateWrapper<>();
updateWrapper
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
 * ==================================================前台页面========================================================================
* */

//商城主页面
@GetMapping("/")
public ModelAndView index() {
ModelAndView mv = new ModelAndView();
//获取轮播图
LambdaQueryWrapper<Banner> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(Banner::getSelected, 1);

//热门商品
LambdaQueryWrapper<Good> goodWrapper = new LambdaQueryWrapper<>();
goodWrapper
.eq(Good::getStatus, 1)
.orderByDesc(Good::getSales)
.last("limit 4");

mv.addObject("goodList", goodService.list(goodWrapper));
mv.addObject("bannerList", bannerService.list(queryWrapper));
mv.setViewName("index/index.html");
return mv;
}

//前台登录界面
@GetMapping("/userLogin")
public ModelAndView UserloginPage() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index/login.html");
return mv;
}

//用户注册界面
@GetMapping("/register")
public ModelAndView register() {
ModelAndView mv = new ModelAndView();
mv.setViewName("register.html");
return mv;
}

//用户修改密码界面
@GetMapping("/updatePwd")
public ModelAndView updatePwd() {
ModelAndView mv = new ModelAndView();
mv.setViewName("index/user_pwd.html");
return mv;
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
53
54
    }
//用户地址
List<Address> addressList = addressService.list(new LambdaQueryWrapper<Address>().eq(Address::getUserId, currentUser.getId()));
LambdaQueryWrapper<Address> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(Address::getUserId, currentUser.getId())
.eq(Address::getDefaulted, 1);
Address address = addressService.getOne(queryWrapper);
ModelAndView mv = new ModelAndView();
mv.addObject("goodList", goodList); //结算商品列表
mv.addObject("totalPrice", totalPrice); //总价格
mv.addObject("addressList", addressList); //地址列表
mv.addObject("defAddress", address == null ? (addressList.size() == 0 ? null : addressList.get(0)) : address); //默认地址
mv.setViewName("index/buy.html");
return mv;
}

//下单接口
@RequestMapping(value = "/createOrder")
public Result createOrder(HttpSession session) {
return orderService.createOrder(
(String) session.getAttribute("cartIds"),
(User) SecurityUtils.getSubject().getPrincipal());
}

@RequestMapping("/getAll")
public ModelAndView userGetAll() {
User currentUser = (User) SecurityUtils.getSubject().getPrincipal();
//通过用户id查订单
LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper
.eq(Order::getUserId, currentUser.getId());
List<Order> orderList = orderService.list(queryWrapper);
for (Order order : orderList) {
Good good = goodService.getById(order.getGoodId()); //订单商品信息
GoodCategory category = categoryService.getById(good.getCategoryId()); //商品分类信息
order.setGoodCategory(category == null ? "其他品牌" : category.getName());
order.setGoodName(good.getName());
order.setGoodSku(good.getSku());
order.setGoodImage(good.getImage());
order.setFmtDateTime(DateUtils.dateFmt(order.getCreateTime()));
}
ModelAndView mv = new ModelAndView();
mv.addObject("orderList", orderList);
mv.setViewName("index/orderList.html");
return mv;
}

//删除订单
@PostMapping("/delete")
public Result delete(@RequestParam(value = "id") String id) {
Order order = orderService.getById(id);
if (order.getStatus() != 4) {
return Result.failure("订单未完成,暂不能删除");


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