基于javaweb的SpringBoot电商书城平台系统设计和实现(java+springboot+mysql+spring+jsp+maven)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

120023312402

130023312402

140023312402

150023312402

160023312402

170023312402

180023312402

190023312402

210023312402

220023312402

230023312402

240023312402

250023312402

260023312402

270023312402

基于javaweb的SpringBoot电商书城平台系统设计和实现(java+springboot+mysql+spring+jsp+maven)

JAVA springboot 电商书城平台系统(已调试) 主要实现了书城网站的浏览、加入购物车操作、订单操作、支付操作、分类查看、搜索、以及后台上传图书信息以及订单管理和一些基本操作功能

主要功能截图如下:

模拟支付宝支付:

主要技术:java springboot springbmvc  shiro  mybatis  mysql  jquery  css  js  jsp  bootstarp.js

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

}

@Override
public BSResult clearCart(HttpServletRequest request, String sessionName) {
request.getSession().removeAttribute(sessionName);
return BSResultUtil.success();
}

@Override
public BSResult deleteCartItem(int bookId, HttpServletRequest request) {

Cart cart = (Cart) request.getSession().getAttribute("cart");
Map<Integer, CartItem> cartItems = cart.getCartItems();
if (cartItems.containsKey(bookId)) {
CartItem cartItem = cartItems.get(bookId);
cart.setTotal(cart.getTotal() - cartItem.getSubTotal());
cartItems.remove(bookId);
}
request.getSession().setAttribute("cart", cart);
return BSResultUtil.success();
}

@Override
public BSResult updateBuyNum(int bookId, int newNum, HttpServletRequest request) {

Cart cart = (Cart) request.getSession().getAttribute("cart");
Map<Integer, CartItem> cartItems = cart.getCartItems();
if (cartItems.containsKey(bookId)) {
//取出订单项所对应的书籍,根据新的购买数量重新计算小计
CartItem cartItem = cartItems.get(bookId);
//不知道是加还是减去商品的数量,所以先减去原来的购物项小计,最后再加新的小计
cart.setTotal(cart.getTotal() - cartItem.getSubTotal());
BookInfo bookInfo = cartItem.getBookInfo();
cartItem.setSubTotal(
bookInfo.getPrice().doubleValue() * newNum);

cartItem.setBuyNum(newNum);
cart.setTotal(cart.getTotal() + cartItem.getSubTotal());
}

request.getSession().setAttribute("cart", cart);
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
        if(categoryList == null){
categoryList = cateService.getCategoryList();
}
//获得书籍列表
List<BookInfo> bookInfos = bookInfoService.findBookListByCateId(categoryList.get(new Random().nextInt(6)).getCateId(), new Random().nextInt(3), 18);
model.addAttribute("bookInfos", bookInfos);

return "index";
}


/**
* 点击首页导航栏分类后来到这个handler
*
* @param cateId
* @param model
* @return
*/
@RequestMapping("/index/category/{cateId}")
public String bookListByCategoryId(@PathVariable("cateId") int cateId, Model model) {


List<BookInfo> bookInfos = bookInfoService.findBookListByCateId(cateId, new Random().nextInt(3), 18);
model.addAttribute("bookInfos", bookInfos);
model.addAttribute("cateId", cateId);
return "index";
}

/**
* 爬取当当网书籍列表数据,并将数据插入到本地mysql数据库中
*
* @param url
* @throws IOException
* @throws ParseException
* @throws SQLException
*/
@PostMapping("/write")
public void write(String url) throws IOException, ParseException, SQLException {
HttpClient httpclient = new DefaultHttpClient(); //创建HttpClient
//先去书籍列表页列表页
List<BookInfo> books = URLEntity.URLParse(httpclient, url, BOOK_CATEGORY); //通过URLEntity获取实体中的信息
//mysql_control.executeInsert(books); //数据库添加数据

writeToMysql.executeInsert(books);
}
}
package org.zdd.bookstore.web.controller;


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
    public String editStore(Store store,Model model){

storeService.updateStore(store);

model.addAttribute("saveMsg", "保存成功");

return "forward:"+store.getStoreId();
}

@RequestMapping("/deletion/{storeId}")
@RequiresPermissions("store-delete")
public String deleteStore(@PathVariable("storeId") int storeId){
storeService.deleteStore(storeId);
return "redirect:/admin/store/list";
}

@RequestMapping("/addition")
@RequiresPermissions("store-add")
public String addStore(Store store){
storeService.addStore(store);
return "redirect:/admin/store/list";
}

}
package org.zdd.bookstore.exception;



@ControllerAdvice
public class BSExceptionHandler {

public static final String BS_ERROR_VIEW_NAME = "exception";

@ExceptionHandler(value = Exception.class)
@ResponseStatus(HttpStatus.OK)
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("/user")
public class UserController {


@Autowired
private IUserService userService;

@Autowired
private IMailService mailService;

@Autowired
private IStoreService storeService;

@Value("${mail.fromMail.addr}")
private String from;

@Value("${my.ip}")
private String ip;

private final String USERNAME_PASSWORD_NOT_MATCH = "用户名或密码错误";

private final String USERNAME_CANNOT_NULL = "用户名不能为空";

@RequestMapping("/login")
public String login(@RequestParam(value = "username", required = false) String username,
@RequestParam(value = "password", required = false) String password,
HttpServletRequest request, Model model) {
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(password)) {
return "login";
}
//未认证的用户
Subject userSubject = SecurityUtils.getSubject();
if (!userSubject.isAuthenticated()) {
UsernamePasswordToken token = new UsernamePasswordToken(username, password);

token.setRememberMe(false);//禁止记住我功能
try {

//登录成功
userSubject.login(token);
User loginUser = (User) userSubject.getPrincipal();
request.getSession().setAttribute("loginUser", loginUser);
Store store = storeService.findStoreByUserId(loginUser.getUserId());
request.getSession().setAttribute("loginStore", store);


SavedRequest savedRequest = WebUtils.getSavedRequest(request);
String url = "/";
if (savedRequest != null) {
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


@Controller
@RequestMapping("admin/privilege")
@RequiresPermissions("privilege-manage")
public class PrivilegeController {


@Autowired
private IPrivilegeService privilegeService;

@ResponseBody
@RequestMapping("/treeNodes")
public List<ZTreeNode> treeNodesJsonData(){
return privilegeService.getZTreeNodes();
}

@ResponseBody
@RequestMapping("/rolePrivileges/{roleId}")
public List<ZTreeNode> treeRolePrivileges(@PathVariable("roleId") int roleId){
return privilegeService.getRolePrivileges(roleId);
}


@ResponseBody
@RequestMapping("/{privId}")
public BSResult getPrivilege(@PathVariable("privId") int privId){
return privilegeService.findById(privId);
}


@RequestMapping("/toEdit/{roleId}")
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

Cart cart = (Cart) request.getSession().getAttribute("cart");
Map<Integer, CartItem> cartItems = cart.getCartItems();
if (cartItems.containsKey(bookId)) {
//取出订单项所对应的书籍,根据新的购买数量重新计算小计
CartItem cartItem = cartItems.get(bookId);
//不知道是加还是减去商品的数量,所以先减去原来的购物项小计,最后再加新的小计
cart.setTotal(cart.getTotal() - cartItem.getSubTotal());
BookInfo bookInfo = cartItem.getBookInfo();
cartItem.setSubTotal(
bookInfo.getPrice().doubleValue() * newNum);

cartItem.setBuyNum(newNum);
cart.setTotal(cart.getTotal() + cartItem.getSubTotal());
}

request.getSession().setAttribute("cart", cart);
return BSResultUtil.success();
}

@Override
public BSResult checkedOrNot(Cart cart, int bookId) {
Map<Integer, CartItem> cartItems = cart.getCartItems();

if (cartItems.containsKey(bookId)) {
CartItem cartItem = cartItems.get(bookId);
if (cartItem.isChecked()) {
//如果之前是true,那就设为false
cartItem.setChecked(false);
cart.setTotal(cart.getTotal() - cartItem.getSubTotal());
cartItem.setSubTotal(0.00);
} else {
//如果之前是false,那就设为true
cartItem.setChecked(true);
cartItem.setSubTotal(cartItem.getBuyNum() * cartItem.getBookInfo().getPrice().doubleValue());
cart.setTotal(cart.getTotal() + cartItem.getSubTotal());

}
return BSResultUtil.success();
} else
return BSResultUtil.build(400, "购物车没有这本书籍!");
}


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