使用SpringMVC+Spring+MyBatis实现图书管理系统——试题讲解

题目:使用SpringMVC+Spring+MyBatis实现图书管理系统——试题讲解

语言和环境

A、实现语言
Java
B、环境要求
JDK1.8、Eclipse、Tomcat7、SpringMVC、Spring、Mybatis、Mysql、Maven

功能要求

使用SSM(SpringMVC+Spring+MyBatis)实现图书管理系统,MySql作为后台数据库,该系统包括用户登录,图书信息列表、图书的新增、修改、删除,并实现分页功能,具体要求如下:

  1. 用户登录功能。打开图书管理系统首页,会出现用户登录界面,输入用户名和密码后,点击登录,如果用户名和密码不正确,给出相应的提示信息,如下图所示。在这里插入图片描述
  2. 图书信息列表显示功能。用户登录成功后,进入图书信息列表显示首页。默认按图书ID降序列出所有的图书。并能够根据用户类型显示登录用户的用户信息。提供新增图书按钮,提供修改链接,提供删除链接。如下图所示:
    在这里插入图片描述
  3. 图书新增功能。点击“新增图书”按钮,跳转到新增的页面,其中书名,作者、出版社、出版日期为必填项,如下图所示。
    在这里插入图片描述
    点击“提交”时,需要执行非空验证,如果书名为空,提示“图书名称不能为空!”,如果作者为空,则提示“作者不能为空!”,出版社和出版日期一样,同样不能为空。日期的输入格式为”年-月-日”,页面效果如下图所示。
    在这里插入图片描述
    提交并保存图书信息后返回到图书信息列表。点击“返回”按钮,直接返回原来的图书信息列表。
  4. 图书修改功能。点击“修改”超链接,显示要修改的图书信息,如下图所示。
    在这里插入图片描述
    提交并更新图书信息后,返回到图书信息列表。点击“返回”按钮,直接返回原来的图书信息列表。
  5. 分页功能。点击第一页、上一页、下一页、最后一页、能够实现分页功能。能够显示总记录数,当前页数/总页数。设置每页条数和转到第几页可以不实现。效果如下图所示。
    在这里插入图片描述
  6. 图书删除功能。点击“删除”超链接,执行删除图书功能,并返回图书列表页。

数据库设计

用户表如下,其他设置参见下表:
在这里插入图片描述

图书信息表如下:
在这里插入图片描述

主要源码

测试数据
-- ----------------------------
-- Table structure for book
-- ----------------------------
DROP TABLE IF EXISTS `book`;
CREATE TABLE `book` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) NOT NULL,
  `author` varchar(100) NOT NULL,
  `publish` varchar(100) NOT NULL,
  `publishdate` date NOT NULL,
  `page` int(11) DEFAULT NULL,
  `price` decimal(8,2) DEFAULT NULL,
  `content` varchar(500) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of book
-- ----------------------------
INSERT INTO `book` VALUES ('1', 'JSP编程', '李四', '电力出版社', '2011-12-02', '300', '40.00', 'JSP编程开发');
INSERT INTO `book` VALUES ('2', 'JSP编程2', '张三', '电力出版社', '2011-12-02', '150', '16.80', 'JSP编程开发');
INSERT INTO `book` VALUES ('3', 'JSP编程3', '张三', '电力出版社', '2011-12-02', '150', '16.80', 'JSP编程开发');
INSERT INTO `book` VALUES ('7', 'java基础', 'tom', '电力', '2010-10-10', '200', '30.00', 'test');
实体类
package com.neu.bean;

import java.math.BigDecimal;
import java.util.Date;

import org.springframework.format.annotation.DateTimeFormat;

public class Book {
       
    private Integer id;
    private String name;
    private String author;
    private String publish;
    @DateTimeFormat(pattern="yyyy-MM-dd")
    private Date publishdate;
    private Integer page;
    private BigDecimal price;
    private String content;
    public Integer getId() {
   
        return id;
    }
    public void setId(Integer id) {
   
        this.id = id;
    }
    public String getName() {
   
        return name;
    }
    public void setName(String name) {
   
        this.name = name;
    }
    public String getAuthor() {
   
        return author;
    }
    public void setAuthor(String author) {
   
        this.author = author;
    }
    public String getPublish() {
   
        return publish;
    }
    public void setPublish(String publish) {
   
        this.publish = publish;
    }
    public Date getPublishdate() {
   
        return publishdate;
    }
    public void setPublishdate(Date publishdate) {
   
        this.publishdate = publishdate;
    }
    public Integer getPage() {
   
        return page;
    }
    public void setPage(Integer page) {
   
        this.page = page;
    }
    public BigDecimal getPrice() {
   
        return price;
    }
    public void setPrice(BigDecimal price) {
   
        this.price = price;
    }
    public String getContent() {
   
        return content;
    }
    public void setContent(String content) {
   
        this.content = content;
    }
}
getpaged.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript">
function goPage(){
    
	var page = document.getElementById("page").value;
	location = "${pageContext.request.contextPath }/book/getPaged.action?pageNum="+page;
}

function del(id){
    
	if(confirm("是否删除?")){
    
		location = "${pageContext.request.contextPath }/book/delete.action?id="+id;
	}
}

function add(){
    
	location = "${pageContext.request.contextPath }/book/getadd.action";
}
</script>
</head>
<body>
	<table border="1" width="600">
		<c:forEach items="${list }" var="book">
			<tr>
				<td>${ book.name }</td>
				<td>${ book.author }</td>
				<td>${ book.publish }</td>
				<td><fmt:formatDate value="${ book.publishdate }" pattern="yyyy-MM-dd"/> </td>
				<td>${ book.page }</td>
				<td>${ book.price }</td>
				<td>${ book.content }</td>
				<td>
					<a href="${pageContext.request.contextPath }/book/edit.action?id=${book.id}">编辑</a> 
					<a href="#" onclick="del(${book.id})">删除</a>
				</td>
			</tr>
		</c:forEach>
		<tr>
			<td colspan="8">
				<input type="button" value="新增图书" onclick="add()">
				共 ${ count } 条记录
				每页 <input type="text" size="1" value="${ pageSize }">条
				第 ${ pageNum } 页/共${ pageCount } 页
				<c:if test="${ pageNum ==1 }">
					<a>第一页</a>
				</c:if>
				<c:if test="${ pageNum  > 1 }">
					<a href="${pageContext.request.contextPath }/book/getPaged.action?pageNum=1">第一页</a>
				</c:if>				
				<c:if test="${ pageNum ==1 }">
					<a>上一页</a>
				</c:if>
				<c:if test="${ pageNum  > 1 }">
					<a href="${pageContext.request.contextPath }/book/getPaged.action?pageNum=${pageNum -1}">上一页</a>
				</c:if>				
				<c:if test="${ pageNum ==pageCount }">
					<a>下一页</a>
				</c:if>
				<c:if test="${ pageNum < pageCount }">
					<a href="${pageContext.request.contextPath }/book/getPaged.action?pageNum=${pageNum +1}">下一页</a>
				</c:if>
				<c:if test="${ pageNum ==pageCount }">
					<a>最后一页</a>
				</c:if>
				<c:if test="${ pageNum < pageCount }">
					<a href="${pageContext.request.contextPath }/book/getPaged.action?pageNum=${ pageCount }">最后一页</a>
				</c:if
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值