Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghuanhao committed Jan 16, 2019
1 parent 3f7250e commit 46f8019
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 107 deletions.
9 changes: 1 addition & 8 deletions Library-DBMS.iml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@
<orderEntry type="library" name="Maven: commons-pool:commons-pool:1.5.4" level="project" />
<orderEntry type="library" name="Maven: mysql:mysql-connector-java:5.1.29" level="project" />
<orderEntry type="library" scope="PROVIDED" name="Maven: javax.servlet:servlet-api:3.0-alpha-1" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.testng:testng:6.8.7" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.10" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.1" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.beanshell:bsh:2.0b4" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: com.beust:jcommander:1.27" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.yaml:snakeyaml:1.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.springframework:spring-test:4.2.2.RELEASE" level="project" />
<orderEntry type="library" name="Maven: org.aspectj:aspectjweaver:1.8.1" level="project" />、
<orderEntry type="library" name="Maven: javax.servlet:jstl:1.2" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.8" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.8" level="project" />
Expand Down
25 changes: 13 additions & 12 deletions src/main/java/com/library/dao/AdminDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@ public class AdminDao {
@Autowired
private JdbcTemplate jdbcTemplate;

private static final String MATCH_ADMIN_ID_SQL="SELECT COUNT(*) FROM admin where admin_id = ? and password = ? ";
private static final String MATCH_ADMIN_NAME_SQL="SELECT COUNT(*) FROM admin where username = ? and password = ? ";
private static final String RE_PASSWORD_SQL="UPDATE admin set password = ? where admin_id = ? ";
private static final String GET_PASSWODD_SQL="SELECT password from admin where admin_id = ?";
private static final String MATCH_ADMIN_ID_SQL = "SELECT COUNT(*) FROM admin where admin_id = ? and password = ? ";
private static final String RE_PASSWORD_SQL = "UPDATE admin set password = ? where admin_id = ? ";
private static final String GET_PASSWORD_SQL = "SELECT password from admin where admin_id = ?";
private static final String GET_USERNAME_SQL = "SELECT username from admin where admin_id = ?";

public int getIdMatchCount(long admin_id,String password){
return jdbcTemplate.queryForObject(MATCH_ADMIN_ID_SQL,new Object[]{admin_id,password},Integer.class);
public int getMatchCount(long adminId, String password) {
return jdbcTemplate.queryForObject(MATCH_ADMIN_ID_SQL, new Object[]{adminId, password}, Integer.class);
}

public int getNameMatchCount(String username,String password){
return jdbcTemplate.queryForObject(MATCH_ADMIN_NAME_SQL,new Object[]{username,password},Integer.class);
public int resetPassword(long adminId, String password) {
return jdbcTemplate.update(RE_PASSWORD_SQL, password, adminId);
}

public int resetPassword(long admin_id,String password){
return jdbcTemplate.update(RE_PASSWORD_SQL,password,admin_id);
public String getPassword(long adminId) {
return jdbcTemplate.queryForObject(GET_PASSWORD_SQL, new Object[]{adminId}, String.class);
}
public String getPassword(long admin_id){
return jdbcTemplate.queryForObject(GET_PASSWODD_SQL,new Object[]{admin_id},String.class);

public String getUsername(long adminId) {
return jdbcTemplate.queryForObject(GET_USERNAME_SQL, new Object[]{adminId}, String.class);
}

}
6 changes: 3 additions & 3 deletions src/main/java/com/library/dao/BookDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ 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 book_info where book_id = ? ";
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,8 +86,8 @@ public ArrayList<Book> getAllBooks() {

}

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

public int addBook(Book book) {
Expand Down
9 changes: 1 addition & 8 deletions src/main/java/com/library/dao/ReaderCardDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,11 @@ public class ReaderCardDao {
private final static String FIND_READER_BY_USERID = "select * from reader_card where reader_id = ? ";
private final static String RE_PASSWORD_SQL = "UPDATE reader_card set password = ? where reader_id = ? ";
private final static String ADD_READERCARD_SQL = "INSERT INTO reader_card values ( ? , ? , ?)";
private final static String UPDATE_READER_USERNAME_SQL = "UPDATE reader_card set username = ? where reader_id = ?";

public int getIdMatchCount(long readerId, String password) {
return jdbcTemplate.queryForObject(MATCH_READER_ID_SQL, new Object[]{readerId, password}, Integer.class);
}

public int getNameMatchCount(String username, String password) {
return jdbcTemplate.queryForObject(MATCH_READER_NAME_SQL, new Object[]{username, password}, Integer.class);
}

public ReaderCard findReaderByReaderId(long readerId) {
final ReaderCard readerCard = new ReaderCard();
jdbcTemplate.query(FIND_READER_BY_USERID, new Object[]{readerId},
Expand All @@ -45,7 +40,5 @@ public int addReaderCard(ReaderInfo readerInfo,String password) {
long readerId = readerInfo.getReaderId();
return jdbcTemplate.update(ADD_READERCARD_SQL, readerId, username, password);
}
public int updateUsername(long readerId, String username) {
return jdbcTemplate.update(UPDATE_READER_USERNAME_SQL, username, readerId);
}

}
7 changes: 7 additions & 0 deletions src/main/java/com/library/dao/ReaderInfoDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class ReaderInfoDao {
private final static String DELETE_READER_INFO_SQL = "DELETE FROM reader_info where reader_id = ? ";
private final static String GET_READER_INFO_SQL = "SELECT * FROM reader_info where reader_id = ? ";
private final static String UPDATE_READER_INFO = "UPDATE reader_info set name = ? ,sex = ? ,birth = ? ,address = ? ,phone = ? where reader_id = ? ";
private final static String UPDATE_READER_CARD = "UPDATE reader_card set username = ? where reader_id = ? ";
private final static String ALL_READER_INFO_SQL = "SELECT * FROM reader_info";

private ReaderInfo getInfoFromResult(ResultSet resultSet) throws SQLException {
Expand Down Expand Up @@ -73,6 +74,12 @@ public int editReaderInfo(ReaderInfo readerInfo) {
return jdbcTemplate.update(UPDATE_READER_INFO, objects);
}

public int editReaderCard(ReaderInfo readerInfo) {
long readerId = readerInfo.getReaderId();
String username = readerInfo.getName();
return jdbcTemplate.update(UPDATE_READER_INFO, username, readerId);
}

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

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

public boolean matchBook(String searchWord){
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/library/service/LoginService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ public boolean hasMatchReader(long readerId,String password){
return readerCardDao.getIdMatchCount(readerId, password)>0;
}

public String getAdminUsername(long adminId) {
return adminDao.getUsername(adminId);
}

public ReaderCard findReaderCardByReaderId(long readerId){
return readerCardDao.findReaderByReaderId(readerId);
}
Expand All @@ -30,7 +34,7 @@ public ReaderInfo findReaderInfoByReaderId(long readerId){
}

public boolean hasMatchAdmin(long adminId,String password){
return adminDao.getIdMatchCount(adminId,password)==1;
return adminDao.getMatchCount(adminId, password) == 1;
}

public boolean adminRePassword(long adminId, String newPassword){
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/library/service/ReaderCardService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,5 @@ public boolean addReaderCard(ReaderInfo readerInfo, String password){
public boolean updatePassword(long readerId, String password){
return readerCardDao.resetPassword(readerId,password)>0;
}
public boolean updateName(long readerId,String name){
return readerCardDao.updateUsername(readerId,name)>0;
}

}
20 changes: 13 additions & 7 deletions src/main/java/com/library/service/ReaderInfoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,27 @@ public class ReaderInfoService {
@Autowired
private ReaderInfoDao readerInfoDao;

public ArrayList<ReaderInfo> readerInfos(){
public ArrayList<ReaderInfo> readerInfos() {
return readerInfoDao.getAllReaderInfo();
}

public boolean deleteReaderInfo(long readerId){
return readerInfoDao.deleteReaderInfo(readerId)>0;
public boolean deleteReaderInfo(long readerId) {
return readerInfoDao.deleteReaderInfo(readerId) > 0;
}

public ReaderInfo getReaderInfo(long readerId){
public ReaderInfo getReaderInfo(long readerId) {
return readerInfoDao.findReaderInfoByReaderId(readerId);
}
public boolean editReaderInfo(ReaderInfo readerInfo){
return readerInfoDao.editReaderInfo(readerInfo)>0;

public boolean editReaderInfo(ReaderInfo readerInfo) {
return readerInfoDao.editReaderInfo(readerInfo) > 0;
}

public boolean editReaderCard(ReaderInfo readerInfo) {
return readerInfoDao.editReaderCard(readerInfo) > 0;
}
public long addReaderInfo(ReaderInfo readerInfo){

public long addReaderInfo(ReaderInfo readerInfo) {
return readerInfoDao.addReaderInfo(readerInfo);
}
}
9 changes: 5 additions & 4 deletions src/main/java/com/library/web/BookController.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ public ModelAndView allBook() {

@RequestMapping("/deletebook.html")
public String deleteBook(HttpServletRequest request, RedirectAttributes redirectAttributes) {
long bookId = Integer.parseInt(request.getParameter("bookId"));
if (bookService.deleteBook(bookId) == 1) {
redirectAttributes.addFlashAttribute("succ", "图书删除成功!");
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", "图书删除失败!");
redirectAttributes.addFlashAttribute("error", "记录删除失败!");
}
return "redirect:/allbooks.html";
}
Expand Down
15 changes: 8 additions & 7 deletions src/main/java/com/library/web/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,24 @@ Object loginCheck(HttpServletRequest request) {
String passwd = request.getParameter("passwd");
boolean isReader = loginService.hasMatchReader(id, passwd);
boolean isAdmin = loginService.hasMatchAdmin(id, passwd);
HashMap<String, String> res = new HashMap<String, String>();
if (isAdmin == false && isReader == false) {
res.put("stateCode", "0");
res.put("msg", "账号或密码错误!");
} else if (isAdmin) {
HashMap<String, String> res = new HashMap<>();
if (isAdmin) {
Admin admin = new Admin();
admin.setAdminId(id);
admin.setPassword(passwd);
String username = loginService.getAdminUsername(id);
admin.setUsername(username);
request.getSession().setAttribute("admin", admin);
res.put("stateCode", "1");
res.put("msg", "管理员登陆成功!");
} else {
} else if (isReader) {
ReaderCard readerCard = loginService.findReaderCardByReaderId(id);
request.getSession().setAttribute("readercard", readerCard);
res.put("stateCode", "2");
res.put("msg", "读者登陆成功!");
} else {
res.put("stateCode", "0");
res.put("msg", "账号或密码错误!");
}
return res;
}
Expand All @@ -78,7 +80,6 @@ public ModelAndView toAdminMain(HttpServletResponse response) {

@RequestMapping("/reader_main.html")
public ModelAndView toReaderMain(HttpServletResponse response) {

return new ModelAndView("reader_main");
}

Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/library/web/ReaderController.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ private ReaderInfo getReaderInfo(long readerId, String name, String sex, String

@RequestMapping("allreaders.html")
public ModelAndView allBooks() {
ArrayList<ReaderInfo> readers = readerInfoService.readerInfos();
ModelAndView modelAndView = new ModelAndView("admin_readers");
ArrayList<ReaderInfo> readers = readerInfoService.readerInfos();
ModelAndView modelAndView = new ModelAndView("admin_readers");
modelAndView.addObject("readers", readers);
return modelAndView;
}
Expand Down Expand Up @@ -87,7 +87,7 @@ public ModelAndView readerInfoEdit(HttpServletRequest request) {
public String readerInfoEditDo(HttpServletRequest request, String name, String sex, String birth, String address, String phone, RedirectAttributes redirectAttributes) {
long readerId = Long.parseLong(request.getParameter("readerId"));
ReaderInfo readerInfo = getReaderInfo(readerId, name, sex, birth, address, phone);
if (readerInfoService.editReaderInfo(readerInfo)) {
if (readerInfoService.editReaderInfo(readerInfo) && readerInfoService.editReaderCard(readerInfo)) {
redirectAttributes.addFlashAttribute("succ", "读者信息修改成功!");
} else {
redirectAttributes.addFlashAttribute("error", "读者信息修改失败!");
Expand Down Expand Up @@ -155,7 +155,7 @@ public ModelAndView readerInfoEditReader(HttpServletRequest request) {
public String readerInfoEditDoReader(HttpServletRequest request, String name, String sex, String birth, String address, String phone, RedirectAttributes redirectAttributes) {
ReaderCard readerCard = (ReaderCard) request.getSession().getAttribute("readercard");
ReaderInfo readerInfo = getReaderInfo(readerCard.getReaderId(), name, sex, birth, address, phone);
if (readerInfoService.editReaderInfo(readerInfo)) {
if (readerInfoService.editReaderInfo(readerInfo) && readerInfoService.editReaderCard(readerInfo)) {
ReaderCard readerCardNew = loginService.findReaderCardByReaderId(readerCard.getReaderId());
request.getSession().setAttribute("readercard", readerCardNew);
redirectAttributes.addFlashAttribute("succ", "信息修改成功!");
Expand Down
7 changes: 6 additions & 1 deletion src/main/webapp/WEB-INF/jsp/admin_books.jsp
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<%@ page import="com.library.domain.Book" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
Expand Down Expand Up @@ -95,9 +94,15 @@
<td><c:out value="${book.isbn}"></c:out></td>
<td><c:out value="${book.price}"></c:out></td>
<td><c:out value="${book.number}"></c:out></td>

<c:if test="${book.number>0}">
<td><a href="lendbook.html?bookId=<c:out value="${book.bookId}"></c:out>"><button type="button" class="btn btn-primary btn-xs">借阅</button></a></td>
</c:if>
<c:if test="${book.number==0}">
<td>
<button type="button" class="btn btn-defalut btn-xs" disabled="disabled">已空</button>
</td>
</c:if>
<td><a href="bookdetail.html?bookId=<c:out value="${book.bookId}"></c:out>"><button type="button" class="btn btn-success btn-xs">详情</button></a></td>
<td><a href="updatebook.html?bookId=<c:out value="${book.bookId}"></c:out>"><button type="button" class="btn btn-info btn-xs">编辑</button></a></td>
<td><a href="deletebook.html?bookId=<c:out value="${book.bookId}"></c:out>"><button type="button" class="btn btn-danger btn-xs">删除</button></a></td>
Expand Down
3 changes: 2 additions & 1 deletion src/main/webapp/WEB-INF/jsp/admin_header.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="login.html"><span class="glyphicon glyphicon-user"></span>&nbsp;${admin.adminId},已登录</a></li>
<li><a href="login.html"><span class="glyphicon glyphicon-user"></span>&nbsp;${admin.username},已登录</a>
</li>
<li><a href="logout.html"><span class="glyphicon glyphicon-log-in"></span>&nbsp;退出</a></li>
</ul>
</div>
Expand Down
5 changes: 4 additions & 1 deletion src/main/webapp/WEB-INF/jsp/admin_lend_list.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@
<td><c:out value="${alog.readerId}"></c:out></td>
<td><c:out value="${alog.lendDate}"></c:out></td>
<td><c:out value="${alog.backDate}"></c:out></td>
<td><a href="deletebook.html?bookId=<c:out value="${alog.ser_num}"></c:out>"><button type="button" class="btn btn-danger btn-xs">删除</button></a></td>
<td>
<a href="deletebook.html?bookId=<c:out value="${alog.ser_num}"></c:out>&readerId=<c:out value="${alog.readerId}"></c:out>">">
<button type="button" class="btn btn-danger btn-xs">删除</button>
</a></td>
</tr>
</c:forEach>
</tbody>
Expand Down
7 changes: 0 additions & 7 deletions src/main/webapp/WEB-INF/jsp/admin_main.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,6 @@
overflow: visible;
background-color: rgb(240,242,245);
}
#newsa{
width:500px;
height: 200px;
position: fixed;
left: 35%;
top:30%;
}
</style>
<script>
$(function () {
Expand Down
16 changes: 6 additions & 10 deletions src/main/webapp/WEB-INF/jsp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
</div>
<div class="panel-body">
<div class="form-group">
<label for="id">用户名</label>
<input type="text" class="form-control" id="id" placeholder="请输入用户名">
<label for="id">账号</label>
<input type="text" class="form-control" id="id" placeholder="请输入账号">
</div>
<div class="form-group">
<label for="passwd">密码</label>
Expand Down Expand Up @@ -96,11 +96,7 @@
var id =$("#id").val();
var passwd=$("#passwd").val();
var remember=$("#remember").prop('checked');
if( id=='' && passwd==''){
$("#info").text("提示:账号和密码不能为空");
}
else if ( id ==''){
if (id == '') {
$("#info").text("提示:账号不能为空");
}
else if( passwd ==''){
Expand All @@ -119,12 +115,12 @@
},
dataType: "json",
success: function(data) {
if(data.stateCode.trim() == "0") {
if (data.stateCode.trim() === "0") {
$("#info").text("提示:账号或密码错误!");
} else if(data.stateCode.trim() == "1") {
} else if (data.stateCode.trim() === "1") {
$("#info").text("提示:登陆成功,跳转中...");
window.location.href="/admin_main.html";
} else if(data.stateCode.trim() == "2"){
} else if (data.stateCode.trim() === "2") {
if(remember){
rememberLogin(id,passwd,remember);
}else {
Expand Down
Loading

0 comments on commit 46f8019

Please sign in to comment.