Java项目:在线书城书店系统(java+jdbc+Servlet+mysql)

news/2024/5/19 1:38:00 标签: java, jdbc, mysql, jsp, servlet

源码获取:博客首页 "资源" 里下载!

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


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

前台页面列表显示处理:

/**
 * @description: 前台页面列表显示处理
 */

@Controller
@RequestMapping("/user/ch")
public class UserBookController {
    // 注入
    @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"));
        }
        // 根据 类目 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);
        }
        session.setAttribute("currentCategory", currentCategory.getId());

        return "/user/user_bookList";
    }

    /**
     * 通过 图书 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);
        // 将 回复信息 设置到 域 汇总
        model.addAttribute("commentExts", commentExts);

        return "/user/bookDetail";
    }

    /**
     * 用于 借阅 图书  操作
     *
     * @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);
            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();
    }


    @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";
    }
}

用户列表信息:

/**
 * 用户列表信息
 */

@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();
/*        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";
    }

    //用户信息修改提交
    @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";
    }


    //用户删除
    @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());
        //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";
    }

    //用户列表模糊查询用户信息(用户名)
    @RequestMapping("/loan_selectLikeName")
    public String Loan_selectLikeName(TbUser tbUser, Model model) {
        Integer online = null;
        TbUserQueryVo tbUserQueryVo = new TbUserQueryVo();
        tbUserQueryVo.setTbUser(tbUser);
        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 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 {
            model.addAttribute("errorMsg", "类目已经存在");
            return "errorMsg";
        }
        return "redirect:/admin/ch/loan_BookClassify.action";
    }

    /**
     * 删除类目信息
     *
     * @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";
    }

    /**
     * 修改 类目关系
     *
     * @param category
     * @return
     */
    @RequestMapping(value = "/updateCategory", method = RequestMethod.POST)
    public String updateCategory(TbCategory category) {

        return "redirect:/admin/ch/loan_BookClassify.action";
    }

    @RequestMapping("/toUpdatePage")
    @ResponseBody
    public TbCategory toUpdatePage(int id) {
        return libraryCategoryService.getCategoryById(id);
    }
}

源码获取:博客首页 "资源" 里下载!


http://www.niftyadmin.cn/n/1554428.html

相关文章

Java项目:汽车出租租赁系统(java+jsp+SSM+maven+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能包括&#xff1a; 车辆管理&#xff0c;出租管理&#xff0c;汽车入库&#xff0c;汽车出租&#xff0c;汽车归还&#xff0c; 客户管理&#xff0c;出租单管理&#xff0c;统计分析等等功…

pxe linux ftp ks,Linux centos PXE无人值守安装 DHCP+TFTP+FTP+Kickstart

网络模式&#xff1a;NAT模式(共享主机的IP地址)DHCP / TFTP IP&#xff1a;192.168.220.137HTTP / FTP / NFS IP&#xff1a;192.168.220.137环境搭建&#xff1a;yum install -y tftp-server dhcp system-config-kickstart vsftpxinetd syslinux1.挂载ISO文件然后把光盘中的文…

Java项目:在线水果商城系统(java+JSP+Spring+SpringMVC +MyBatis+html+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a; 区分为管理员用户和普通用户&#xff0c;普通用户&#xff1a;用户注册登录&#xff0c;首页水果展示&#xff0c;商品分类展示&#xff0c;购物车添加&#xff0c;下单&…

linux系统及程序迁移,linux系统迁移

在raspberry pi开发中&#xff0c;经常修改系统配置。有时候也不知道该了什么东西&#xff0c;所以就制作了几个镜像来保存进度。问题&#xff1a;由于sd卡的实际大小是不固定的&#xff0c;所以16G的系统镜像有时候不能直接写入。如果用更大的sd卡去烧写&#xff0c;那么会有空…

Java项目:宿舍管理系统(java+jsp+SSM+Spring+mysql)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a;包括学生管理&#xff0c;班级管理&#xff0c;宿舍管理&#xff0c;人员信息维 护。维修登记&#xff0c;卫生管理&#xff0c;访客管理等等。 二、项目运行 环境配置&am…

Java项目:在线旅游系统(java+jsp+SSM+Spring+mysql+maven)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 一、项目简述 功能&#xff1a;用户的登录注册&#xff0c;旅游景点的展示&#xff0c;旅游预订&#xff0c;收藏&#xff0c;购买&#xff0c;以及酒店住宿留言等等&#xff0c;后台管理员&#xff0c;订单…

linux初始化quota数据库,如何在Linux上启动Quota

序言: 这份文件的版权由 Albert M.C. Tam (bertiescn.org) 所保留。同意这份文件的使用、复制&#xff0c;因此非商业性的散布是允许的&#xff0c;但是所有的拷贝以及&#xff0f;或是没有修改直接援用的文件上须有作者与编者的名字及这份注意事项。这份文件是因为希望能有所帮…

Java项目:在线考试系统(单选,多选,判断,填空,简答题)(java+Springboot+ssm+mysql+html+maven)

源码获取&#xff1a;博客首页 "资源" 里下载&#xff01; 功能&#xff1a; 学生信息 班级 专业 学号 姓名 在线考试 成绩查询 个人信息 密码修改 教师管理 教师编号 姓名 所教科目 题库管理 单选题 多选题 填空题 判断题&#xff0c;简答题&#xff08;人工…