基于javaweb的二手图书商城平台(java+ssm+jsp+js+jquery+mysql)
运行环境
Java≥8、MySQL≥5.7、Tomcat≥8
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的二手图书商城平台(java+SSM+JSP+JS+jquery+Mysql)
项目介绍
用户角色包含以下功能: 用户登录,查看商品详情,按分类查看,查看我的书架,上传二手书等功能。 PS:这个没有管理员角色。
环境需要
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项目:是;
技术栈
- 后端:Spring+SpringMVC+Mybatis 2. 前端:JSP+CSS+JavaScript+jquery
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven; 若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,输入localhost:8080/ssm_sebook_market 登录
图书管理控制层:
@Controller
public class BookController {
@Autowired
private BookService bookService;
@Autowired
private LendService lendService;
private Date getDate(String pubstr) {
try {
SimpleDateFormat df = new SimpleDateFormat(“yyyy-MM-dd”);
return df.parse(pubstr);
} catch (ParseException e) {
e.printStackTrace();
return new Date();
@RequestMapping(“/queryBook.html”)
public ModelAndView queryBookDo(String searchWord) {
if (bookService.matchBook(searchWord)) {
ArrayList books = bookService.queryBook(searchWord);
ModelAndView modelAndView = new ModelAndView(“admin_books”);
modelAndView.addObject(“books”, books);
return modelAndView;
} else {
return new ModelAndView(“admin_books”, “error”, “没有匹配的图书”);
@RequestMapping(“/reader_querybook_do.html”)
public ModelAndView readerQueryBookDo(String searchWord) {
if (bookService.matchBook(searchWord)) {
ArrayList books = bookService.queryBook(searchWord);
ModelAndView modelAndView = new ModelAndView(“reader_books”);
modelAndView.addObject(“books”, books);
return modelAndView;
} else {
return new ModelAndView(“reader_books”, “error”, “没有匹配的图书”);
@RequestMapping(“/admin_books.html”)
public ModelAndView adminBooks() {
ArrayList books = bookService.getAllBooks();
ModelAndView modelAndView = new ModelAndView(“admin_books”);
modelAndView.addObject(“books”, books);
return modelAndView;
@RequestMapping(“/book_add.html”)
public ModelAndView addBook() {
return new ModelAndView(“admin_book_add”);
@RequestMapping(“/book_add_do.html”)
public String addBookDo(@RequestParam(value = “pubstr”) String pubstr, Book book, RedirectAttributes redirectAttributes) {
book.setPubdate(getDate(pubstr));
if (bookService.addBook(book)) {
redirectAttributes.addFlashAttribute(“succ”, “图书添加成功!”);
} else {
redirectAttributes.addFlashAttribute(“succ”, “图书添加失败!”);
return “redirect:/admin_books.html”;
@RequestMapping(“/updatebook.html”)
public ModelAndView bookEdit(HttpServletRequest request) {
long bookId = Long.parseLong(request.getParameter(“bookId”));
Book book = bookService.getBook(bookId);
ModelAndView modelAndView = new ModelAndView(“admin_book_edit”);
modelAndView.addObject(“detail”, book);
return modelAndView;
@RequestMapping(“/book_edit_do.html”)
public String bookEditDo(@RequestParam(value = “pubstr”) String pubstr, Book book, RedirectAttributes redirectAttributes) {
book.setPubdate(getDate(pubstr));
if (bookService.editBook(book)) {
redirectAttributes.addFlashAttribute(“succ”, “图书修改成功!”);
} else {
redirectAttributes.addFlashAttribute(“error”, “图书修改失败!”);
return “redirect:/admin_books.html”;
@RequestMapping(“/admin_book_detail.html”)
public ModelAndView adminBookDetail(HttpServletRequest request) {
long bookId = Long.parseLong(request.getParameter(“bookId”));
Book book = bookService.getBook(bookId);
ModelAndView modelAndView = new ModelAndView(“admin_book_detail”);
modelAndView.addObject(“detail”, book);
return modelAndView;
@RequestMapping(“/reader_book_detail.html”)
public ModelAndView readerBookDetail(HttpServletRequest request) {
long bookId = Long.parseLong(request.getParameter(“bookId”));
Book book = bookService.getBook(bookId);
ModelAndView modelAndView = new ModelAndView(“reader_book_detail”);
modelAndView.addObject(“detail”, book);
return modelAndView;
@RequestMapping(“/admin_header.html”)
public ModelAndView admin_header() {
return new ModelAndView(“admin_header”);
@RequestMapping(“/reader_header.html”)
public ModelAndView reader_header() {
return new ModelAndView(“reader_header”);
@RequestMapping(“/reader_books.html”)
public ModelAndView readerBooks(HttpServletRequest request) {
ArrayList books = bookService.getAllBooks();
ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute(“readercard”);
ArrayList myAllLendList = lendService.myLendList(readerCard.getReaderId());
ArrayList myLendList = new ArrayList<>();
for (Lend lend : myAllLendList) {
// 是否已归还
if (lend.getBackDate() == null) {
myLendList.add(lend.getBookId());
ModelAndView modelAndView = new ModelAndView(“reader_books”);
modelAndView.addObject(“books”, books);
modelAndView.addObject(“myLendList”, myLendList);
return modelAndView;
登录管理控制层:
@Controller
public class LoginController {
private LoginService loginService;
@Autowired
public void setLoginService(LoginService loginService) {
this.loginService = loginService;
@RequestMapping(value = {“/”, “/login.html”})
public String toLogin(HttpServletRequest request) {
request.getSession().invalidate();
return “index”;
@RequestMapping(“/logout.html”)
public String logout(HttpServletRequest request) {
request.getSession().invalidate();
return “redirect:/login.html”;
@RequestMapping(“/admin_main.html”)
public ModelAndView toAdminMain(HttpServletResponse response) {
return new ModelAndView(“admin_main”);
@RequestMapping(“/reader_main.html”)
public ModelAndView toReaderMain(HttpServletResponse response) {
return new ModelAndView(“reader_main”);
@RequestMapping(“/admin_repasswd.html”)
public ModelAndView reAdminPasswd() {
return new ModelAndView(“admin_repasswd”);
@RequestMapping(“/admin_repasswd_do”)
public String reAdminPasswdDo(HttpServletRequest request, String oldPasswd, String newPasswd, String reNewPasswd, RedirectAttributes redirectAttributes) {
Admin admin = (Admin) request.getSession().getAttribute(“admin”);
long id = admin.getAdminId();
String password = loginService.getAdminPassword(id);
if (password.equals(oldPasswd)) {
if (loginService.adminRePassword(id, newPasswd)) {
redirectAttributes.addFlashAttribute(“succ”, “密码修改成功!”);
return “redirect:/admin_repasswd.html”;
} else {
redirectAttributes.addFlashAttribute(“error”, “密码修改失败!”);
return “redirect:/admin_repasswd.html”;
} else {
redirectAttributes.addFlashAttribute(“error”, “旧密码错误!”);
return “redirect:/admin_repasswd.html”;
@RequestMapping(“/reader_repasswd.html”)
public ModelAndView reReaderPasswd() {
return new ModelAndView(“reader_repasswd”);
@RequestMapping(“/reader_repasswd_do”)
public String reReaderPasswdDo(HttpServletRequest request, String oldPasswd, String newPasswd, String reNewPasswd, RedirectAttributes redirectAttributes) {
ReaderCard reader = (ReaderCard) request.getSession().getAttribute(“readercard”);
long id = reader.getReaderId();
String password = loginService.getReaderPassword(id);
if (password.equals(oldPasswd)) {
if (loginService.readerRePassword(id, newPasswd)) {
redirectAttributes.addFlashAttribute(“succ”, “密码修改成功!”);
return “redirect:/reader_repasswd.html”;
} else {
redirectAttributes.addFlashAttribute(“error”, “密码修改失败!”);
return “redirect:/reader_repasswd.html”;
} else {
redirectAttributes.addFlashAttribute(“error”, “旧密码错误!”);
return “redirect:/reader_repasswd.html”;
//配置404页面
@RequestMapping(“*”)
public String notFind() {
return “404”;
配置管理控制层:
@Configuration
@EnableWebMvc
@ComponentScan(“com.library.controller”)
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setSuffix(“.jsp”);
return resolver;
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler(“/img/**”)
.addResourceLocations(“/static/img/”);
registry.addResourceHandler(“/js/**”).addResourceLocations(“/static/js/”);
registry.addResourceHandler(“/css/**”).addResourceLocations(“/static/css/”);