Java项目:SSM电子书网站管理系统

作者主页:源码空间站2022

 简介:Java领域优质创作者、Java项目、学习资料、技术互助

文末获取源码

项目介绍

本项目包含管理员、用户两种角色;

管理员角色包含以下功能:

登录页面,管理员管理书籍,用户管理等功能。

用户角色包含以下功能:

首页,用户登录页面,电子书查看页面,下载电子书,查看分类,用户上传图书,查看个人中心,添加反馈,查看反馈等功能。

环境需要

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+JavaScript

使用说明

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

4. 运行项目,在浏览器中输入http://localhost:8080/ssm_ebooknet 登录

运行截图

相关代码

图书控制器

package com.lianshuwang.controller;

import com.lianshuwang.domin.Book;
import com.lianshuwang.domin.BookType;
import com.lianshuwang.domin.Upload;
import com.lianshuwang.domin.User;
import com.lianshuwang.helper.PageHelper;
import com.lianshuwang.service.BookService;
import com.lianshuwang.service.UserService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by admin on 2019/10/15.
 */
@Controller
public class BookController {

    @Autowired
    private BookService bookService;
    @Autowired
    private UserService userService;

    private static final Log logger = LogFactory.getLog(BookController.class);

    @RequestMapping(value = "/bookList")
    public String getBookList(String bookType, String smallType, @RequestParam(value = "pageId",defaultValue = "1") int pageId, Model model) {
        logger.info("you are visiting the books list page!");
        List<BookType> smallTypes;
        smallTypes = bookService.getSmallTypesOfBook(bookType);
        model.addAttribute("smallTypesOfBook", smallTypes);
        model.addAttribute("bookType",bookType);
        PageHelper page = new PageHelper();
        page.setCurrentPage(pageId);
        if (null == smallType) {
            int sumOfBooks = bookService.getTotalOfLTBooks(smallTypes);
            page.setTotalRows(sumOfBooks);
            List<Book> books = bookService.getLargeTypeBooks(smallTypes,page);
            model.addAttribute("currentPage",pageId);
            model.addAttribute("totalPage",page.getTotalPage());
            model.addAttribute("books",books);
        } else {
            int type_id = 0;
            for (BookType sBookType : smallTypes) {
                if (sBookType.getSmall_type_name().equals(smallType)) {
                    type_id = sBookType.getId();
                    break;
                }
            }
            int sumOfBooks = bookService.getTotalOfSTBooks(type_id);
            page.setTotalRows(sumOfBooks);
            List<Book> books = bookService.getSmallTypeBooks(type_id,page);
            model.addAttribute("currentPage",pageId);
            model.addAttribute("totalPage",page.getTotalPage());
            model.addAttribute("books",books);
            model.addAttribute("smallType",smallType);
        }
        return "bookList";
    }

    @RequestMapping(value = "/bookDetail")
    public String bookDetail(long bookID, Model model) {
        Book book;
        book = bookService.getBookDetail(bookID);
        Upload upload;
        upload = bookService.getUploadInfo(bookID);
        Date uploadedDate = upload.getUploadedDate();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String uploadDate = dateFormat.format(uploadedDate);
        User user;
        user = userService.queryById(upload.getUploader());
        model.addAttribute("book",book);
        model.addAttribute("uploadedDate",uploadDate);
        model.addAttribute("uploader",user.getUserName());
        model.addAttribute("format",book.getBook_format().toUpperCase());
        logger.info("you are looking up the book:" + book.getBook_title());
        return "bookDetail";
    }

    @RequestMapping(value = "/getBookCover")
    public void getBookCover(String coverPath, HttpServletResponse response, HttpSession session) {
        String basePath = session.getServletContext().getRealPath("/") + "ebooks/" + coverPath;

        InputStream in = null;
        BufferedInputStream bis = null;
        OutputStream out = null;
        BufferedOutputStream bos = null;
        File file = new File(basePath);
        if (!file.exists() || file.isDirectory()) {
            return;
        }
        try {
            in = new FileInputStream(basePath);
            bis = new BufferedInputStream(in);
            byte[] data = new byte[1024];
            int bytes = 0;
            out = response.getOutputStream();
            bos = new BufferedOutputStream(out);
            while ((bytes = bis.read(data, 0, data.length)) != -1) {
                bos.write(data, 0, bytes);
            }
            bos.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bos != null) {
                    bos.close();
                }
                if (out != null) {
                    out.close();
                }
                if (bis != null) {
                    bis.close();
                }
                if (in != null) {
                    in.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    @RequestMapping(value = "/book_download")
    public void getBookDownload(long bookID, String filePath, HttpServletResponse response) {
        response.setContentType("text/html;charset=utf-8");
        String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        try {
            long fileLength = new File(filePath).length();
            response.setContentType("application/x-msdownload");
            response.setHeader("Content-disposition", "attachment; filename="
                    + new String(fileName.getBytes("utf-8"), "ISO8859-1"));
            response.setHeader("Content-Length", String.valueOf(fileLength));
            bis =new BufferedInputStream(new FileInputStream(filePath));
            bos = new BufferedOutputStream(response.getOutputStream());
            byte[] buff = new byte[2018];
            int bytesRead;
            while (-1  != (bytesRead = bis.read(buff, 0, buff.length))) {
                bos.write(buff, 0, bytesRead);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (bis != null) {
                    bis.close();
                }
                if (bos != null) {
                    bos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
            bookService.addDownloadTimes(bookID);
            logger.info("you are downloading the book, the book file is " + fileName);
        }
    }

    @RequestMapping(value = "/bookSearch")
    public String bookSearch(String searchBy, String searchTxt, Model model) throws ParseException {
        logger.info("you are searching book!");
        logger.info("The search context is " + searchTxt);
        List<Book> books = bookService.searchBook(searchBy, searchTxt);
        model.addAttribute("books", books);
        model.addAttribute("searchTxt",searchTxt);
        return "searchResult";
    }

}

如果也想学习本系统,下面领取。关注并回复:129ssm 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值