基于javaweb+jsp的在线书城书店系统(java+jdbc+Servlet+mysql)

基于javaweb+jsp的在线书城书店系统(java+jdbc+Servlet+mysql)

一个基于Java的网上书店的设计与实现,归纳出了几个模块,首先是登录注册模块,购物车模块,订单模块,个人中心模块,用户管理模块,图书管理模块等。

该项目是java技术的实战操作,采用了MVC设计模式,查询分页,持久化层方法的封装等等,对java技术的巩固很有帮助,为J2EE的学习打下基础,适用于课程设计,毕业设计。

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

适用

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

    public String addUser(TbUser tbUser) {
        //注册时间
        tbUser.setRegisterdate(System.currentTimeMillis());
        //not online
        tbUser.setIsonline(0);
        tbUser.setPassword(tbUser.getUsername());
        int i = loan_userInfoList.addUser(tbUser);
        if (i > 0) {
            System.out.println("添加成功!");
            return "redirect:loan_userList.action";
        }
        return "redirect:loan_userList.action";
    }
    //用户列表模糊查询用户信息(用户名)
        model.addAttribute("userList", userList);
        return "admin/loan_userList";
    }
    //用户信息修改页面
    @RequestMapping("/loan_editUser")
    public String editUser(Integer id, Model model) {
        TbUser tbUser = loan_userInfoList.updataUserInfo(id);
        model.addAttribute("tbUser", tbUser);
        return "admin/loan_editUser";
    }
    //用户信息修改提交
    @RequestMapping("/editUser")
    public String editUser(TbUser tbUser, Model model) {
        int i = loan_userInfoList.editUser(tbUser);
        if (i > 0) {
            return "redirect:loan_userList.action";
        }
        //进行数据回显
        model.addAttribute("tbUser", tbUser);
        return "admin/loan_editUser";
            libraryQuery = new TbLibraryQuery();
            libraryQuery.setCateId((Integer) session.getAttribute("currentCategory"));
        }
        // 根据 类目 id
        // 若 当前 类目 为 父类目 则获取 其 下面 的 所有子类目
        // 若 当前 类目 为 子类目 则获取 其 同级 类目
        List<TbCategory> categoryList = libraryCategoryService.getCategoryByCid(libraryQuery.getCateId());
        // 获取当前类目信息
        TbCategory currentCategory = libraryCategoryService.getCategoryById(libraryQuery.getCateId());
        // 按照条件进行查询
        PageCount<TblibraryExt> libraryPageCount = libraryService.findLibraryByAll(libraryQuery, pageCount);
        // model 将数据设置到域中
        model.addAttribute("subCategoryList", categoryList);
        model.addAttribute("libraryPageCount", libraryPageCount);
        // 默认
        if (currentCategory == null) {
            currentCategory = new TbCategory();
            currentCategory.setId(0);
        }
    /**
     * 通过 图书 id 查询 图书详细信息
     *
     * @param id
     * @return
     */
    @RequestMapping("/bookId")
    public String toBookInfo(int id, Model model) {
        BookExt bookInfo = libraryService.getBookInfoById(id);
        // 将 时间戳 进行转换
        Long dateSS = bookInfo.getLibrary().getCreatedate();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String formatDate = simpleDateFormat.format(new Date(dateSS * 1000));
        bookInfo.setFormatDate(formatDate);
        // 通过 图书id 获取 回复信息
        List<CommentExt> commentExts = commentService.findCommentByBookId(id);
        // 将 查询的 图书信息 设置到 域 中
        model.addAttribute("bookInfo", bookInfo);
        // 将 回复信息 设置到 域 汇总
        // 获取 session 中的用户信息
        ActiveUser activeUser = (ActiveUser) session.getAttribute("activeUser");
        TbUser tbUser = new TbUser();
        tbUser.setId(activeUser.getUserid());
        comment.setUserId(tbUser.getId());
        libraryService.addCommentInfo(comment);
        return "ok";
    }
}
用户列表信息:
/**
 * 用户列表信息
 */
@Controller
@RequestMapping("/admin")
public class Loan_UserInfoController {
    @Autowired
    private Loan_UserInfoList loan_userInfoList;
    //查询用户信息列表
    @RequestMapping("/loan_userList")
    public String userList(Model model) {
        List<TbUser> userList = loan_userInfoList.findUserList();
        TbUser tbUser = new TbUser();
        tbUser.setId(activeUser.getUserid());
        order.setUserId(tbUser.getId());
        // 插入数据
        libraryService.jieyueBookById(order);
        return "redirect:/user/ch/bookId.action?id=" + order.getBookId();
    }
    @RequestMapping("/commitInfo")
    @ResponseBody
    public String commitComment(HttpSession session, TbComment comment) {
        // 获取 session 中的用户信息
        ActiveUser activeUser = (ActiveUser) session.getAttribute("activeUser");
        TbUser tbUser = new TbUser();
        tbUser.setId(activeUser.getUserid());
    //查询用户信息列表
    @RequestMapping("/loan_userList")
    public String userList(Model model) {
        List<TbUser> userList = loan_userInfoList.findUserList();
/*        for(TbUser t : userList) {
            System.out.println(t);
        }*/
        model.addAttribute("userList", userList);
        return "admin/loan_userList";
    }
    //用户信息修改页面
    @RequestMapping("/loan_editUser")
    public String editUser(Integer id, Model model) {
        TbUser tbUser = loan_userInfoList.updataUserInfo(id);
        model.addAttribute("tbUser", tbUser);
        return "admin/loan_editUser";
    }
        }
        // 根据 类目 id
        // 若 当前 类目 为 父类目 则获取 其 下面 的 所有子类目
        // 若 当前 类目 为 子类目 则获取 其 同级 类目
        List<TbCategory> categoryList = libraryCategoryService.getCategoryByCid(libraryQuery.getCateId());
        // 获取当前类目信息
        TbCategory currentCategory = libraryCategoryService.getCategoryById(libraryQuery.getCateId());
        // 按照条件进行查询
        PageCount<TblibraryExt> libraryPageCount = libraryService.findLibraryByAll(libraryQuery, pageCount);
        // model 将数据设置到域中
        model.addAttribute("subCategoryList", categoryList);
        model.addAttribute("libraryPageCount", libraryPageCount);
        // 默认
图书类别处理:
/**
 * @description: 图书类别处理
 */
@Controller
@RequestMapping("/admin/ch/category")
public class CategoryController {
    //注入
    @Autowired
    private LibraryCategoryService libraryCategoryService;
    /**
     * 添加 图书类目
     *
     * @param category 图书类目信息
     * @param session  添加人
     * @return url
     * @author hiseico
     */
    @RequestMapping(value = "/addCategory", method = RequestMethod.POST)
    public String addCategory(TbCategory category, HttpSession session, Model model) {
        List<TbCategory> categoryList = libraryCategoryService.getCategoryAll();
        boolean is = false;
        for (TbCategory tbCategory : categoryList) {
            if (category.getCatname().equals(tbCategory.getCatname())) {
     * @param session  添加人
     * @return url
     * @author hiseico
     */
    @RequestMapping(value = "/addCategory", method = RequestMethod.POST)
    public String addCategory(TbCategory category, HttpSession session, Model model) {
        List<TbCategory> categoryList = libraryCategoryService.getCategoryAll();
        boolean is = false;
        for (TbCategory tbCategory : categoryList) {
            if (category.getCatname().equals(tbCategory.getCatname())) {
                is = true;
                break;
            }
        }
        if (!is) {
            // 添加 数据到 数据库,并 修改 父类目
            libraryCategoryService.addBookCategory(category, session);
        } else {
    @Autowired
    private Loan_UserInfoList loan_userInfoList;
    //查询用户信息列表
    @RequestMapping("/loan_userList")
    public String userList(Model model) {
        List<TbUser> userList = loan_userInfoList.findUserList();
/*        for(TbUser t : userList) {
            System.out.println(t);
        }*/
        model.addAttribute("userList", userList);
        return "admin/loan_userList";
    }
    //用户信息修改页面
    @RequestMapping("/loan_editUser")
    public String editUser(Integer id, Model model) {
        TbUser tbUser = loan_userInfoList.updataUserInfo(id);
        model.addAttribute("tbUser", tbUser);
        return "admin/loan_editUser";
    }
    //用户信息修改提交
    public String jieyueBook(HttpSession session, Model model, String oid, String kkid, TbOrder order) {
        if (null != kkid) {
            TbRecord tbRecord = recordMapper.selectByPrimaryKey(Integer.valueOf(kkid));
            tbRecord.setReturnbook(2); //2代表挂失
            recordMapper.updateByPrimaryKey(tbRecord);
            model.addAttribute("successMsg", "图书挂失成功");
            return "errorMsg";
        }
        if (null != oid) {
            TbRecord tbOrder = recordMapper.selectByPrimaryKey(Integer.valueOf(oid));
            // 插入数据
            tbOrder.setBackdate(tbOrder.getBackdate() + 3 * 30 * 24 * 60 * 60);
            recordMapper.updateByPrimaryKey(tbOrder);
            model.addAttribute("successMsg", "续借三个月成功");
            return "errorMsg";
        }
        // 获取 session 中的用户信息
        ActiveUser activeUser = (ActiveUser) session.getAttribute("activeUser");
        TbUser tbUser = new TbUser();
        tbUser.setId(activeUser.getUserid());
        order.setUserId(tbUser.getId());
        // 插入数据
        libraryService.jieyueBookById(order);
        return "redirect:/user/ch/bookId.action?id=" + order.getBookId();
     * 修改 类目关系
     *
     * @param category
     * @return
     */
    @RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
    public String updateCategory(TbCategory category) {
        return "redirect:/admin/ch/loan_BookClassify.action";
    }
    @RequestMapping("/toUpdatePage")
    @ResponseBody
前台页面列表显示处理:
/**
 * @description: 前台页面列表显示处理
 */
@Controller
@RequestMapping("/user/ch")
public class UserBookController {
            return "redirect:loan_userList.action";
        }
        //进行数据回显
        model.addAttribute("tbUser", tbUser);
        return "admin/loan_editUser";
    }
    //用户删除
    @RequestMapping("/loan_deleteUser")
    public String loan_deleteUser(Integer id) {
        int i = loan_userInfoList.deleteUser(id);
        if (i > 0) {
     * @param session 用于 取 用户信息
     * @param order   用户借阅关联信息
     * @return
     */
    @RequestMapping("/jieyue_book")
    public String jieyueBook(HttpSession session, Model model, String oid, String kkid, TbOrder order) {
        if (null != kkid) {
            TbRecord tbRecord = recordMapper.selectByPrimaryKey(Integer.valueOf(kkid));
            tbRecord.setReturnbook(2); //2代表挂失
            recordMapper.updateByPrimaryKey(tbRecord);
            model.addAttribute("successMsg", "图书挂失成功");
            return "errorMsg";
        }
        if (null != oid) {
            TbRecord tbOrder = recordMapper.selectByPrimaryKey(Integer.valueOf(oid));
            // 插入数据
            tbOrder.setBackdate(tbOrder.getBackdate() + 3 * 30 * 24 * 60 * 60);
    @RequestMapping("/loan_editUser")
    public String editUser(Integer id, Model model) {
        TbUser tbUser = loan_userInfoList.updataUserInfo(id);
        model.addAttribute("tbUser", tbUser);
        return "admin/loan_editUser";
    }
    //用户信息修改提交
    @RequestMapping("/editUser")
    public String editUser(TbUser tbUser, Model model) {
        int i = loan_userInfoList.editUser(tbUser);
        if (i > 0) {
    }
    /**
     * 修改 类目关系
     *
     * @param category
     * @return
     */
    @RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
    public String updateCategory(TbCategory category) {
        return "redirect:/admin/ch/loan_BookClassify.action";
    }
    @RequestMapping("/toUpdatePage")
    @ResponseBody
前台页面列表显示处理:
        return "redirect:/user/ch/bookId.action?id=" + order.getBookId();
    }
    @RequestMapping("/commitInfo")
    @ResponseBody
    public String commitComment(HttpSession session, TbComment comment) {
        // 获取 session 中的用户信息
        ActiveUser activeUser = (ActiveUser) session.getAttribute("activeUser");
        TbUser tbUser = new TbUser();
        tbUser.setId(activeUser.getUserid());
        comment.setUserId(tbUser.getId());
        libraryService.addCommentInfo(comment);
        return "ok";
    }
}
用户列表信息:
/**
 * 用户列表信息
public class CategoryController {
    //注入
    @Autowired
    private LibraryCategoryService libraryCategoryService;
    /**
     * 添加 图书类目
     *
     * @param category 图书类目信息
     * @param session  添加人
     * @return url
     * @author hiseico
     */
    @Autowired
    private LibraryService libraryService;
    @Autowired
    private LibraryCategoryService libraryCategoryService;
    @Autowired
    private CommentService commentService;
    @Autowired
    private TbOrderMapper orderMapper;
    @Autowired
    private TbRecordMapper recordMapper;
    @Value("${LOGIN_USER}")
    private String LOGIN_USER;  // 当前登录用户的 session 存储 属性名
    @RequestMapping("/user_bookList")
    @Autowired
    private LibraryService libraryService;
    @Autowired
    private LibraryCategoryService libraryCategoryService;
    @Autowired
    private CommentService commentService;
    @Autowired
    private TbOrderMapper orderMapper;
    @Autowired
    private TbRecordMapper recordMapper;
    @Value("${LOGIN_USER}")
    private String LOGIN_USER;  // 当前登录用户的 session 存储 属性名
    @RequestMapping("/user_bookList")
    public String toLibraryListByCid(TbLibraryQuery libraryQuery, PageCount pageCount, Model model, HttpSession session) {
        if (libraryQuery == null || libraryQuery.getCateId() == null) {
            libraryQuery = new TbLibraryQuery();
            libraryQuery.setCateId((Integer) session.getAttribute("currentCategory"));
        }
        return "admin/loan_userList";
    }
    //用户信息修改页面
    @RequestMapping("/loan_editUser")
    public String editUser(Integer id, Model model) {
        TbUser tbUser = loan_userInfoList.updataUserInfo(id);
        model.addAttribute("tbUser", tbUser);
        return "admin/loan_editUser";
    }
    //用户信息修改提交
    @RequestMapping("/editUser")
    public String editUser(TbUser tbUser, Model model) {
        int i = loan_userInfoList.editUser(tbUser);
        if (i > 0) {
            return "redirect:loan_userList.action";
        tbUserQueryVo.setOnline(online);
        List<TbUser> userList = loan_userInfoList.selectLikeName(tbUserQueryVo);
        model.addAttribute("userList", userList);
        return "admin/loan_userList";
    }
}
图书类别处理:
/**
 * @description: 图书类别处理
 */
@Controller
@RequestMapping("/admin/ch/category")
public class CategoryController {
    //注入
    @Autowired
    private LibraryCategoryService libraryCategoryService;
    /**
     * 添加 图书类目
     *
     * @param category 图书类目信息
     * @param session  添加人
     * @return
     */
    @RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
    public String updateCategory(TbCategory category) {
        return "redirect:/admin/ch/loan_BookClassify.action";
    }
    @RequestMapping("/toUpdatePage")
    @ResponseBody
前台页面列表显示处理:
/**
 * @description: 前台页面列表显示处理
 */
@Controller
    public String toLibraryListByCid(TbLibraryQuery libraryQuery, PageCount pageCount, Model model, HttpSession session) {
        if (libraryQuery == null || libraryQuery.getCateId() == null) {
            libraryQuery = new TbLibraryQuery();
            libraryQuery.setCateId((Integer) session.getAttribute("currentCategory"));
        }
        // 根据 类目 id
        // 若 当前 类目 为 父类目 则获取 其 下面 的 所有子类目
        // 若 当前 类目 为 子类目 则获取 其 同级 类目
        List<TbCategory> categoryList = libraryCategoryService.getCategoryByCid(libraryQuery.getCateId());
        // 获取当前类目信息
        TbCategory currentCategory = libraryCategoryService.getCategoryById(libraryQuery.getCateId());
        // 按照条件进行查询
        PageCount<TblibraryExt> libraryPageCount = libraryService.findLibraryByAll(libraryQuery, pageCount);
    }
    /**
     * 通过 图书 id 查询 图书详细信息
     *
     * @param id
     * @return
     */
    @RequestMapping("/bookId")
    public String toBookInfo(int id, Model model) {
        BookExt bookInfo = libraryService.getBookInfoById(id);
        // 将 时间戳 进行转换
        Long dateSS = bookInfo.getLibrary().getCreatedate();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String formatDate = simpleDateFormat.format(new Date(dateSS * 1000));
        bookInfo.setFormatDate(formatDate);
        // 通过 图书id 获取 回复信息
        List<CommentExt> commentExts = commentService.findCommentByBookId(id);
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/delCategory", method = RequestMethod.GET)
    public String delCategory(int id) {
        // 通过 类目id 删除数据
        libraryCategoryService.delBookCategoryById(id);
        return "redirect:/admin/ch/loan_BookClassify.action";
    }
    /**
        return "admin/loan_editUser";
    }
    //用户删除
    @RequestMapping("/loan_deleteUser")
    public String loan_deleteUser(Integer id) {
        int i = loan_userInfoList.deleteUser(id);
        if (i > 0) {
            return "redirect:loan_userList.action";
        }
        return "redirect:loan_userList.action";
    }
    //用户添加
    @RequestMapping("/loan_addUser")
    public String addUser(TbUser tbUser) {
        //注册时间
        tbUser.setRegisterdate(System.currentTimeMillis());

  • 1
    点赞
  • 32
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
javaweb是一种以Java为基础的web开发技术,它包括了servletjsp等相关技术。servletJavaEE规范中的一种组件,它主要用于处理用户发送的HTTP请求和返回HTTP响应。servlet可以接收前端页面传来的数据,然后对数据进行处理并返回给前端页面。mysql是一种关系型数据库管理系统,它能够存储大量的数据并提供有效的数据管理和查询功能。在javaweb开发中,我们可以通过servlet来连接mysql数据库,从而实现数据的持久化存储和操作。 jsp是一种基于Java的动态网页开发技术,它可以将Java代码嵌入到HTML页面中,从而实现动态页面的生成和展示。jsp可以使用Java代码来获取数据库中的数据并将其显示在前端页面上,实现了前后端的数据交互。 service是一种用于实现业务逻辑的组件或类,它负责处理具体的业务功能。在javaweb开发中,我们可以将业务逻辑封装在service中,然后在servlet中调用相应的service方法,实现对数据的处理和操作。 考试中无框架要求表示不可以使用现成的框架或库来完成开发任务,需要手动编写相关代码。在考试中,可以考察学生对javaweb技术的理解和应用能力,要求学生能够熟练地使用servletjsp等相关技术,并能够编写出符合需求的代码。此外,对于数据库操作,学生还需要了解mysql的基本操作和相关的jdbc编程技巧。 总而言之,javaweb servlet mysql jsp service的考试是考察学生对javaweb开发技术的掌握程度和应用能力的一种考试形式,学生需要熟练地使用这些技术,并能够灵活运用到实际的开发场景中。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值