Skip to content

Commit

Permalink
修改
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghuanhao committed Jan 17, 2019
1 parent c086279 commit 0ca603c
Show file tree
Hide file tree
Showing 22 changed files with 116 additions and 158 deletions.
6 changes: 0 additions & 6 deletions src/main/java/com/library/dao/BookDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class BookDao {
private JdbcTemplate jdbcTemplate;

private final static String ADD_BOOK_SQL = "INSERT INTO book_info VALUES(NULL ,?,?,?,?,?,?,?,?,?,?)";
private final static String DELETE_BOOK_SQL = "delete from lend_list where book_id = ? and reader_id = ? ";
private final static String EDIT_BOOK_SQL = "update book_info set name= ? ,author= ? ,publish= ? ,ISBN= ? ,introduction= ? ,language= ? ,price= ? ,pub_date= ? ,class_id= ? ,number= ? where book_id= ? ";
private final static String QUERY_ALL_BOOKS_SQL = "SELECT * FROM book_info ";
private final static String QUERY_BOOK_SQL = "SELECT * FROM book_info WHERE book_id like ? or name like ? ";
Expand Down Expand Up @@ -86,10 +85,6 @@ public ArrayList<Book> getAllBooks() {

}

public int deleteBook(long bookId, long readerId) {
return jdbcTemplate.update(DELETE_BOOK_SQL, bookId, readerId);
}

public int addBook(Book book) {
return jdbcTemplate.update(ADD_BOOK_SQL, getObjectFromBook(book));
}
Expand All @@ -111,5 +106,4 @@ public int editBook(Book book) {
return jdbcTemplate.update(EDIT_BOOK_SQL, objects);
}


}
12 changes: 6 additions & 6 deletions src/main/java/com/library/dao/LendDao.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.library.dao;

import com.library.domain.Lend;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;
import com.library.domain.Lend;

import java.sql.ResultSet;
import java.sql.SQLException;
Expand All @@ -18,16 +18,12 @@ public class LendDao {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");

private final static String RETURN_BOOK_ONE_SQL = "UPDATE lend_list SET back_date = ? WHERE book_id = ? AND reader_id = ? AND back_date is NULL";

private final static String RETURN_BOOK_TWO_SQL = "UPDATE book_info SET number = number + 1 WHERE book_id = ? ";

private final static String LEND_BOOK_ONE_SQL = "INSERT INTO lend_list VALUES (NULL , ? , ? , ? , NULL)";

private final static String LEND_BOOK_TWO_SQL = "UPDATE book_info SET number = number - 1 WHERE book_id = ? ";

private final static String LEND_LIST_SQL = "SELECT * FROM lend_list";

private final static String MY_LEND_LIST_SQL = "SELECT * FROM lend_list WHERE reader_id = ? ";
private final static String DELETE_BOOK_SQL = "DELETE FROM lend_list WHERE ser_num = ?";

public int returnBookOne(long bookId, long readerId) {
return jdbcTemplate.update(RETURN_BOOK_ONE_SQL, df.format(new Date()), bookId, readerId);
Expand Down Expand Up @@ -76,4 +72,8 @@ public ArrayList<Lend> myLendList(long readerId) {
});
return list;
}

public int deleteBook(long serNum) {
return jdbcTemplate.update(DELETE_BOOK_SQL, serNum);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/library/dao/ReaderInfoDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ public int editReaderInfo(ReaderInfo readerInfo) {
public int editReaderCard(ReaderInfo readerInfo) {
long readerId = readerInfo.getReaderId();
String username = readerInfo.getName();
return jdbcTemplate.update(UPDATE_READER_INFO, username, readerId);
return jdbcTemplate.update(UPDATE_READER_CARD, username, readerId);
}

//返回reader_id

public long addReaderInfo(ReaderInfo readerInfo) {
Object[] objects = getObjectFromInfo(readerInfo);
if (jdbcTemplate.update(ADD_READER_INFO_SQL, objects) > 0) {
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/library/service/BookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ public ArrayList<Book> getAllBooks(){
return bookDao.getAllBooks();
}

public int deleteBook(long bookId, long readerId) {
return bookDao.deleteBook(bookId, readerId);
}

public boolean matchBook(String searchWord){
return bookDao.matchBook(searchWord)>0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/library/service/LendService.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,8 @@ public ArrayList<Lend> myLendList(long readerId){
return lendDao.myLendList(readerId);
}

public int deleteBook(long serNum) {
return lendDao.deleteBook(serNum);
}

}
18 changes: 3 additions & 15 deletions src/main/java/com/library/web/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ public ModelAndView queryBookDo(String searchWord) {
}
}

@RequestMapping("/reader_querybook.html")
@RequestMapping("/reader_books.html")
public ModelAndView readerQueryBook() {
return new ModelAndView("reader_book_query");
return new ModelAndView("reader_books");

}

Expand All @@ -67,20 +67,8 @@ public ModelAndView allBook() {
return modelAndView;
}

@RequestMapping("/deletebook.html")
public String deleteBook(HttpServletRequest request, RedirectAttributes redirectAttributes) {
long bookId = Long.parseLong(request.getParameter("bookId"));
long readerId = Long.parseLong(request.getParameter("readerId"));
if (bookService.deleteBook(bookId, readerId) == 1) {
redirectAttributes.addFlashAttribute("succ", "记录删除成功!");
} else {
redirectAttributes.addFlashAttribute("error", "记录删除失败!");
}
return "redirect:/allbooks.html";
}

@RequestMapping("/book_add.html")
public ModelAndView addBook(HttpServletRequest request) {
public ModelAndView addBook() {
return new ModelAndView("admin_book_add");
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/library/web/LendController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,19 @@ public String bookReturn(HttpServletRequest request, RedirectAttributes redirect
return "redirect:/allbooks.html";
}

@RequestMapping("/deletebook.html")
public String deleteBook(HttpServletRequest request, RedirectAttributes redirectAttributes) {
long serNum = Long.parseLong(request.getParameter("serNum"));
if (lendService.deleteBook(serNum) == 1) {
redirectAttributes.addFlashAttribute("succ", "记录删除成功!");
} else {
redirectAttributes.addFlashAttribute("error", "记录删除失败!");
}
return "redirect:/lendlist.html";
}

@RequestMapping("/lendlist.html")
public ModelAndView lendList() {
public ModelAndView lendList(HttpServletRequest request) {
ModelAndView modelAndView = new ModelAndView("admin_lend_list");
modelAndView.addObject("list", lendService.lendList());
return modelAndView;
Expand Down
6 changes: 0 additions & 6 deletions src/main/java/com/library/web/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,11 @@ public ModelAndView toReaderMain(HttpServletResponse response) {

@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);
Expand All @@ -109,14 +107,10 @@ public String reAdminPasswdDo(HttpServletRequest request, String oldPasswd, Stri
return "redirect:/admin_repasswd.html";
}
}

;

//配置404页面
@RequestMapping("*")
public String notFind() {
return "404";
}


}
1 change: 0 additions & 1 deletion src/main/java/com/library/web/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,5 @@ public void addResourceHandlers(ResourceHandlerRegistry registry) {
.addResourceLocations("/static/images/");
registry.addResourceHandler("/js/**").addResourceLocations("/static/js/");
registry.addResourceHandler("/css/**").addResourceLocations("/static/css/");
registry.addResourceHandler("/html/**").addResourceLocations("/static/html/");
}
}
120 changes: 59 additions & 61 deletions src/main/webapp/WEB-INF/jsp/admin_book_add.jsp
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>图书信息添加</title>
<link rel="stylesheet" href="css/bootstrap.min.css">
<script src="js/jquery-3.2.1.js"></script>
<script src="js/bootstrap.min.js" ></script>
<script src="js/bootstrap.min.js"></script>
<style>
body{
background-color: rgb(240,242,245);
body {
background-color: rgb(240, 242, 245);
}
</style>
<script>
Expand All @@ -20,66 +20,64 @@

<div id="header"></div>
<div style="position: relative;top: 10%;width: 80%;margin-left: 10%">
<form action="book_add_do.html" method="post" id="addbook" >
<div class="form-group">
<label for="name">图书名</label>
<input type="text" class="form-control" name="name" id="name" placeholder="请输入书名">
</div>
<div class="form-group">
<label for="author">作者</label>
<input type="text" class="form-control" name="author" id="author" placeholder="请输入作者名">
</div>
<div class="form-group">
<label for="publish">出版社</label>
<input type="text" class="form-control" name="publish" id="publish" placeholder="请输入出版社">
</div>
<div class="form-group">
<label for="isbn">ISBN</label>
<input type="text" class="form-control" name="isbn" id="isbn" placeholder="请输入ISBN">
</div>
<div class="form-group">
<label for="introduction">简介</label>
<textarea class="form-control" rows="3" name="introduction" id="introduction" placeholder="请输入简介"></textarea>
</div>
<div class="form-group">
<label for="language">语言</label>
<input type="text" class="form-control" name="language" id="language" placeholder="请输入语言">
</div>
<div class="form-group">
<label for="price">价格</label>
<input type="text" class="form-control" name="price" id="price" placeholder="请输入价格">
</div>
<div class="form-group">
<label for="pubstr">出版日期</label>
<input type="date" class="form-control" name="pubstr" id="pubstr" placeholder="请输入出版日期">
</div>
<div class="form-group">
<label for="classId">分类号</label>
<input type="text" class="form-control" name="classId" id="classId" placeholder="请输入分类号">
</div>
<div class="form-group">
<label for="number">数量</label>
<input type="text" class="form-control" name="number" id="number" placeholder="请输入图书数量">
</div>
<form action="book_add_do.html" method="post" id="addbook">
<div class="form-group">
<label for="name">图书名</label>
<input type="text" class="form-control" name="name" id="name" placeholder="请输入书名">
</div>
<div class="form-group">
<label for="author">作者</label>
<input type="text" class="form-control" name="author" id="author" placeholder="请输入作者名">
</div>
<div class="form-group">
<label for="publish">出版社</label>
<input type="text" class="form-control" name="publish" id="publish" placeholder="请输入出版社">
</div>
<div class="form-group">
<label for="isbn">ISBN</label>
<input type="text" class="form-control" name="isbn" id="isbn" placeholder="请输入ISBN">
</div>
<div class="form-group">
<label for="introduction">简介</label>
<textarea class="form-control" rows="3" name="introduction" id="introduction"
placeholder="请输入简介"></textarea>
</div>
<div class="form-group">
<label for="language">语言</label>
<input type="text" class="form-control" name="language" id="language" placeholder="请输入语言">
</div>
<div class="form-group">
<label for="price">价格</label>
<input type="text" class="form-control" name="price" id="price" placeholder="请输入价格">
</div>
<div class="form-group">
<label for="pubstr">出版日期</label>
<input type="date" class="form-control" name="pubstr" id="pubstr" placeholder="请输入出版日期">
</div>
<div class="form-group">
<label for="classId">分类号</label>
<input type="text" class="form-control" name="classId" id="classId" placeholder="请输入分类号">
</div>
<div class="form-group">
<label for="number">数量</label>
<input type="text" class="form-control" name="number" id="number" placeholder="请输入图书数量">
</div>


<input type="submit" value="添加" class="btn btn-success btn-sm" class="text-left">
<script>
function mySubmit(flag){
return flag;
}
$("#addbook").submit(function () {
if($("#name").val()==''||$("#author").val()==''||$("#publish").val()==''||$("#isbn").val()==''||$("#introduction").val()==''||$("#language").val()==''||$("#price").val()==''||$("#pubstr").val()==''||$("#classId").val()==''||$("#pressmark").val()==''||$("#number").val()==''){
alert("请填入完整图书信息!");
return mySubmit(false);
}
})
</script>
</form>
<input type="submit" value="添加" class="btn btn-success btn-sm" class="text-left">
<script>
function mySubmit(flag) {
return flag;
}
$("#addbook").submit(function () {
if ($("#name").val() == '' || $("#author").val() == '' || $("#publish").val() == '' || $("#isbn").val() == '' || $("#introduction").val() == '' || $("#language").val() == '' || $("#price").val() == '' || $("#pubstr").val() == '' || $("#classId").val() == '' || $("#pressmark").val() == '' || $("#number").val() == '') {
alert("请填入完整图书信息!");
return mySubmit(false);
}
})
</script>
</form>
</div>



</body>
</html>
5 changes: 1 addition & 4 deletions src/main/webapp/WEB-INF/jsp/admin_book_edit.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,10 @@
</div>
<input type="submit" value="确定" class="btn btn-success btn-sm" class="text-left">
<script>
function mySubmit(flag){
return flag;
}
$("#addbook").submit(function () {
if($("#name").val()==''||$("#author").val()==''||$("#publish").val()==''||$("#isbn").val()==''||$("#introduction").val()==''||$("#language").val()==''||$("#price").val()==''||$("#pubstr").val()==''||$("#classId").val()==''||$("#number").val()==''){
alert("请填入完整图书信息!");
return mySubmit(false);
return false;
}
})
</script>
Expand Down
5 changes: 1 addition & 4 deletions src/main/webapp/WEB-INF/jsp/admin_book_lend.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,10 @@
<br/>
<input type="submit" value="确定" class="btn btn-success btn-sm" class="text-left">
<script>
function mySubmit(flag){
return flag;
}
$("#lendbook").submit(function () {
if($("#name").val()==''||$("#readerId").val()==''){
alert("请填入完整图书信息!");
return mySubmit(false);
return false;
}
})
</script>
Expand Down
5 changes: 1 addition & 4 deletions src/main/webapp/WEB-INF/jsp/admin_books.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@
</div>
</form>
<script>
function mySubmit(flag){
return flag;
}
$("#searchform").submit(function () {
var val=$("#search").val();
if(val==''){
alert("请输入关键字");
return mySubmit(false);
return false;
}
})
</script>
Expand Down
Loading

0 comments on commit 0ca603c

Please sign in to comment.