基于javaweb+jsp的网上电子书城项目

基于javaweb+jsp的网上电子书城项目,第1张

项目描述:
spring mvc +jsp实现的简单书城项目,可以在支付宝沙箱内实现支付
运行环境:
jdk8+tomcat9+mysql+IntelliJ IDEA
项目技术:
spring+spring mvc+mybatis+jsp+maven





适用

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

    @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<BookInfo> recommendBookList = bookInfoService.findBookListByCateId(bookInfo.getBookCategoryId(), 1, 5);
        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
                        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());
@RequiresPermissions("book-manage")
public class AdminBookController {
    @Autowired
    private IBookInfoService bookInfoService;
    @Autowired
    private BookDescMapper bookDescMapper;
    @Autowired
    private IStoreService storeService;
    @Value("${image.url.prefix}")
    private String urlPrefix;
    @RequestMapping("toAddition")
    @RequiresPermissions("book-add")
    public String toAddition() {
        return "admin/book/add";
    }
    /**
     * 添加书籍
     *
     */
    @RequestMapping("/addition")
    @RequiresPermissions("book-add")
    public String addBook(BookInfo bookInfo, String bookDesc, MultipartFile pictureFile, HttpServletRequest request) throws Exception {
        uploadPicture(bookInfo, pictureFile, request);
        bookInfoService.saveBook(bookInfo, bookDesc);
        return "redirect:/admin/book/list";
    }
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/echo")
    @RequiresPermissions("book-edit")
    public String echo(int bookId, Model model) throws BSException {
        BookInfo bookInfo = bookInfoService.adminFindById(bookId);
        BookDesc bookDesc = bookDescMapper.selectByPrimaryKey(bookInfo.getBookId());
        model.addAttribute("bookInfo", bookInfo);
        model.addAttribute("bookDesc", bookDesc);
        return "admin/book/edit";
    }
    @RequestMapping("/update")
    @RequiresPermissions("book-edit")
    public String updateBook(BookInfo bookInfo, String bookDesc, String keywords, MultipartFile pictureFile, HttpServletRequest request, RedirectAttributes ra) throws Exception {
        uploadPicture(bookInfo, pictureFile, request);
        BookInfo originBook = bookInfoService.findById(bookInfo.getBookId());
        bookInfoService.updateBook(bookInfo, bookDesc);
        //更新图片后,删除原来的图片
        String realPath = request.getServletContext().getRealPath("/");
        File uploadPic = new File(realPath + originBook.getImageUrl());
        uploadPic.delete();
        //重定向到书籍列表
        ra.addAttribute("keywords", keywords);
            return BSResultUtil.build(400, "密码不能为空");
        }
        return userService.compareAndChange(userId,oldPassword,newPassword);
    }
}
订单管理控制层:
@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
     */
        // 为了防止用户不是点击前台按钮提交表单造成的错误,后台也需要判断
        if ((Boolean) isExist.getData()) {
        	user.setActive("1");
            BSResult bsResult = userService.saveUser(user);
            //获得未激活的用户
            User userNotActive = (User) bsResult.getData();
          /*  try {
                mailService.sendHtmlMail(user.getEmail(), "<dd书城>---用户激活---",
                        "<html><body><a href='http://"+ip+"/user/active?activeCode=" + userNotActive.getCode() + "'>亲爱的" + user.getUsername() +
                                ",请您点击此链接前往激活a>body>html>");
            } 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";
        }
    }
        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判断用户名是否存在,
        // 为了防止用户不是点击前台按钮提交表单造成的错误,后台也需要判断
     * 填写订单信息页面
     *
     * @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";
    @RequiresPermissions("book-add")
    public String toAddition() {
        return "admin/book/add";
    }
    /**
     * 添加书籍
     *
     */
    @RequestMapping("/addition")
    @RequiresPermissions("book-add")
    public String addBook(BookInfo bookInfo, String bookDesc, MultipartFile pictureFile, HttpServletRequest request) throws Exception {
        uploadPicture(bookInfo, pictureFile, request);
        bookInfoService.saveBook(bookInfo, bookDesc);
        return "redirect:/admin/book/list";
    }
    /**
     * 书籍列表
     *
     */
    @RequestMapping(value = "/list")
    @RequiresPermissions("book-query")
    public String bookList(@RequestParam(defaultValue = "", required = false) String keywords,
                           @RequestParam(value = "page", defaultValue = "1", required = false) int page,
                           HttpSession session,
                           Model model) {
        keywords = keywords.trim();

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/725301.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-26
下一篇 2022-04-26

发表评论

登录后才能评论

评论列表(0条)

保存