基于javaweb的图书商城系统(java+ssm+jsp+javascript+html+mysql)

基于javaweb的图书商城系统(java+ssm+jsp+javascript+html+mysql)

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

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

适用

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

功能说明

20220819204951

20220819204953

20220819204954

20220819204955

20220819204956

20220819204957

20220819204958

20220819204959

基于javaweb+mysql的图书商城系统(java+SSM+Maven+JSP+javascriipt+html+Mysql)

项目介绍

本项目分为前后台,分为管理员与用户两种角色,用户登录前台,管理员登录后台; 管理员角色包含以下功能: 管理员登录,订单管理,顾客管理,添加顾客,图书管理,添加图书,类目列表管理,添加类目,用户管理等功能。 用户角色包含以下功能: 查看书店首页,用户注册,用户登录,查看图书详情,加入购物车,提交订单,查看我的订单等功能。

环境需要

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

技术栈

  1. 后端:spring+springmvc+mybatis 2. 前端:JSP+css+javascriipt+jQuery+html

使用说明

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

订单管理控制层:

@Controller

@RequestMapping(“/order”)

public class OrderController {

@Autowired

private IOrderService orderService;

@Autowired

private ICartService cartService;

@Autowired

private IBookInfoService bookInfoService;

/**

  • 填写订单信息页面

  • @param bookId

  • @param buyNum

  • @param request

  • @return

*/

@GetMapping(“/info”)

public String orderInfo(@RequestParam(required = false, defaultValue = “0”) int bookId,

@RequestParam(required = false, defaultValue = “0”) int buyNum,

HttpServletRequest request) throws BSException {

if (bookId != 0) {

//点了立即购买,放到request域中,也session的立即购买域中以区分购物车中的书籍

BookInfo bookInfo = bookInfoService.findById(bookId);

if (bookInfo != null) {

BSResult bsResult = cartService.addToCart(bookInfo, null, buyNum);

request.getSession().setAttribute(“buyNowCart”, bsResult.getData());

request.setAttribute(“cart”, bsResult.getData());

return “order_info”;

} else {

request.setAttribute(“exception”, “不好意思,书籍库存不足或不存在了!”);

return “exception”;

//没有点立即购买,购物车中的总金额大于0才让填写订单信息

Cart cart = (Cart) request.getSession().getAttribute(“cart”);

if (cart != null && cart.getTotal() > 0) {

return “order_info”;

} else {

return “cart”;

@GetMapping(“/payPage/{orderId}”)

public String toPay(@PathVariable(“orderId”) String orderId, Model model) {

BSResult bsResult = orderService.findOrderById(orderId);

if (bsResult.getCode() == 200) {

model.addAttribute(“order”, bsResult.getData());

return “payment”;

return “exception”;

@RequestMapping(“/deletion/{orderId}”)

public String deletion(@PathVariable(“orderId”) String orderId) {

BSResult bsResult = orderService.deleteOrder(orderId);

if (bsResult.getCode() == 200) {

return “redirect:/order/list”;

return “exception”;

/**

  • 订单列表

  • @return

*/

@GetMapping(“/list”)

public String orderList(HttpServletRequest request) {

User loginUser = (User) request.getSession().getAttribute(“loginUser”);

List orderCustoms = orderService.findOrdersByUserId(loginUser.getUserId());

request.setAttribute(“orderCustoms”, orderCustoms);

return “order_list”;

/**

  • 创建订单

  • @return

*/

@PostMapping(“/creation”)

public String createOrder(User userDTO, String express, int payMethod, HttpServletRequest request) {

//立即购买,优先创建订单

Cart buyNowCart = (Cart) request.getSession().getAttribute(“buyNowCart”);

User loginUser = (User) request.getSession().getAttribute(“loginUser”);

userDTO.setUserId(loginUser.getUserId());

userDTO.setZipCode(loginUser.getZipCode());

if (buyNowCart != null) {

BSResult bsResult = orderService.createOrder(buyNowCart, userDTO, express, payMethod);

if (bsResult.getCode() == 200) {

request.setAttribute(“order”, bsResult.getData());

cartService.clearCart(request, “buyNowCart”);

return “payment”;

} else {

request.setAttribute(“exception”, bsResult.getMessage());

return “exception”;

//普通购物车

Cart cart = (Cart) request.getSession().getAttribute(“cart”);

if (cart != null) {

BSResult bsResult = orderService.createOrder(cart, userDTO, express, payMethod);

if (bsResult.getCode() == 200) {

request.setAttribute(“order”, bsResult.getData());

cartService.clearCart(request, “cart”);

return “payment”;

} else {

request.setAttribute(“exception”, bsResult.getMessage());

return “exception”;

} else {

request.setAttribute(“exception”, “购物车为空!”);

return “exception”;

/**

  • 确认收货

  • @param orderId

  • @return

*/

@RequestMapping(“/confirm/{orderId}”)

public String confirmReceiving(@PathVariable(“orderId”) String orderId, Model model) {

BSResult bsResult = orderService.confirmReceiving(orderId);

if (bsResult.getCode() == 200) {

return “redirect:/order/list”;

} else {

model.addAttribute(“exception”, bsResult.getMessage());

return “exception”;

用户管理控制层:

@Controller

@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) {

url = savedRequest.getRequestUrl();

if(url.contains(request.getContextPath())){

url = url.replace(request.getContextPath(),“”);

if(StringUtils.isEmpty(url) || url.equals(“/favicon.ico”)){

url = “/”;

return “redirect:” + url;

} catch (UnknownAccountException | IncorrectCredentialsException uae) {

model.addAttribute(“loginMsg”, USERNAME_PASSWORD_NOT_MATCH);

return “login”;

} catch (LockedAccountException lae) {

model.addAttribute(“loginMsg”, “账户已被冻结!”);

return “login”;

} catch (AuthenticationException ae) {

model.addAttribute(“loginMsg”, “登录失败!”);

return “login”;

} else {

//用户已经登录

return “redirect:/index”;

@RequestMapping(“/info”)

public String personInfo(){

return “user_info”;

/* @RequestMapping(“/login1”)

public String login1(@RequestParam(value = “username”, required = false) String username,

@RequestParam(value = “password”, required = false) String password,

Model model, HttpServletRequest request) {

if (StringUtils.isEmpty(username)) {

model.addAttribute(“loginMsg”, USERNAME_CANNOT_NULL);

return “login”;

if (StringUtils.isEmpty(password)) {

model.addAttribute(“loginMsg”, “密码不能为空”);

return “login”;

BSResult bsResult = userService.login(username, password);

//登录校验失败

if (bsResult.getData() == null) {

model.addAttribute(“loginMsg”, bsResult.getMessage());

return “login”;

//登录校验成功,重定向到首页

User user = bsResult.getData();

//置密码为空

user.setPassword(“”);

request.getSession().setAttribute(“user”, user);

return “redirect:/”;

*/

//shiro框架帮我们注销

@RequestMapping(“/logout”)

@CacheEvict(cacheNames=“authorizationCache”,allEntries = true)

public String logout() {

SecurityUtils.getSubject().logout();

return “redirect:/page/login”;

/**

  • 注册 检验用户名是否存在

  • @param username

  • @return

*/

@RequestMapping(“/checkUserExist”)

@ResponseBody

public BSResult checkUserExist(String username) {

if (StringUtils.isEmpty(username)) {

return BSResultUtil.build(200, USERNAME_CANNOT_NULL, false);

return userService.checkUserExistByUsername(username);

/**

  • 注册,发激活邮箱

  • @param user

  • @return

*/

@RequestMapping(“/register”)

public String register(User user, Model model) {

BSResult isExist = checkUserExist(user.getUsername());

//尽管前台页面已经用ajax判断用户名是否存在,

// 为了防止用户不是点击前台按钮提交表单造成的错误,后台也需要判断

if ((Boolean) isExist.getData()) {

user.setActive(“1”);

BSResult bsResult = userService.saveUser(user);

//获得未激活的用户

User userNotActive = (User) bsResult.getData();

/* try {

mailService.sendHtmlMail(user.getEmail(), “<dd书城>—用户激活—”,

亲爱的” + user.getUsername() +

“,请您点击此链接前往激活”);

} catch (Exception e) {

e.printStackTrace();

model.addAttribute(“registerError”, “发送邮件异常!请检查您输入的邮箱地址是否正确。”);

return “fail”;

}*/

model.addAttribute(“username”, user.getUsername());

return “register_success”;

} else {

//用户名已经存在,不能注册

model.addAttribute(“registerError”, isExist.getMessage());

return “register”;

@RequestMapping(“/active”)

public String activeUser(String activeCode, Model model) {

BSResult bsResult = userService.activeUser(activeCode);

if (!StringUtils.isEmpty(bsResult.getData())) {

model.addAttribute(“username”, bsResult.getData());

return “active_success”;

} else {

model.addAttribute(“failMessage”, bsResult.getMessage());

return “fail”;

@RequestMapping(“/update”)

@ResponseBody

public BSResult updateUser(User user, HttpSession session){

User loginUser = (User) session.getAttribute(“loginUser”);

loginUser.setNickname(user.getNickname());

loginUser.setLocation(user.getLocation());

loginUser.setDetailAddress(user.getDetailAddress());

loginUser.setGender(user.getGender());

loginUser.setUpdated(new Date());

loginUser.setPhone(user.getPhone());

loginUser.setIdentity(user.getIdentity());

loginUser.setPhone(user.getPhone());

BSResult bsResult = userService.updateUser(loginUser);

session.setAttribute(“loginUser”, loginUser);

return bsResult;

@RequestMapping(“/password/{userId}”)

@ResponseBody

public BSResult changePassword(@PathVariable(“userId”) int userId,String oldPassword,String newPassword){

if(StringUtils.isEmpty(oldPassword) || StringUtils.isEmpty(newPassword)){

return BSResultUtil.build(400, “密码不能为空”);

return userService.compareAndChange(userId,oldPassword,newPassword);

图书信息管理控制层:

@Controller

@RequestMapping(“/book”)

public class BookInfoController {

@Autowired

private IBookInfoService bookInfoService;

@Autowired

private BookDescMapper bookDescMapper;

/**

  • 查询某一本书籍详情

  • @param bookId

  • @param model

  • @return

*/

@RequestMapping(“/info/{bookId}”)

public String bookInfo(@PathVariable(“bookId”) Integer bookId, Model model) throws BSException {

//查询书籍

BookInfo bookInfo = bookInfoService.findById(bookId);

//查询书籍推荐列表

List recommendBookList = bookInfoService.findBookListByCateId(bookInfo.getBookCategoryId(), 1, 5);

//查询书籍详情

BookDesc bookDesc = bookDescMapper.selectByPrimaryKey(bookId);

//增加访问量

bookInfoService.addLookMount(bookInfo);

Collections.shuffle(recommendBookList);

model.addAttribute(“bookInfo”, bookInfo);

model.addAttribute(“bookDesc”, bookDesc);

model.addAttribute(“recommendBookList”, recommendBookList);

return “book_info”;

/**

  • 通过关键字和书籍分类搜索书籍列表

  • @param keywords

  • @return

*/

@RequestMapping(“/list”)

public String bookSearchList(@RequestParam(defaultValue = “”, required = false) String keywords,

@RequestParam(defaultValue = “0”, required = false) int cateId,//分类Id,默认为0,即不按照分类Id查

@RequestParam(defaultValue = “1”, required = false) int page,

@RequestParam(defaultValue = “6”, required = false) int pageSize,

Model model) {

keywords = keywords.trim();

PageInfo bookPageInfo = bookInfoService.findBookListByCondition(keywords, cateId, page, pageSize,0);//storeId为0,不按照商店Id查询

model.addAttribute(“bookPageInfo”, bookPageInfo);

model.addAttribute(“keywords”, keywords);

model.addAttribute(“cateId”, cateId);

return “book_list”;


  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值