热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

作者主页:源码空间站2022简介:Java领域优质创作者、Java项目、学习资料、技术互助文末获取源码项目介绍本项目包含管理员、用户两种角色ÿ


作者主页:源码空间站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 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 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 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 books = bookService.searchBook(searchBy, searchTxt);
model.addAttribute("books", books);
model.addAttribute("searchTxt",searchTxt);
return "searchResult";
}
}

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



推荐阅读
author-avatar
我就是老笨2013
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有