books = ServiceFactory.getIBookServiceInstance().selectByName(book_name);
37 | json.put("data", books);
38 | json.put("code", "000000");
39 | json.put("message", "请求成功");
40 | response.getWriter().println(json);
41 |
42 | } else {
43 | json.put("code", "111111");
44 | json.put("message", "缺少参数!");
45 | response.getWriter().println(json);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/borrow/QueryBorrowByISBNServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.borrow;
2 |
3 | import java.io.IOException;
4 | import java.math.BigDecimal;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | import com.book.entity.Book;
12 | import com.book.entity.Borrow;
13 | import com.book.service.ServiceFactory;
14 | import com.book.util.StringUtils;
15 |
16 | import cn.hutool.json.JSONObject;
17 |
18 | /**
19 | * Servlet implementation class BookServlet
20 | */
21 | public class QueryBorrowByISBNServlet extends HttpServlet {
22 |
23 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
24 | throws ServletException, IOException {
25 | doPost(request, response);
26 | }
27 |
28 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
29 | throws ServletException, IOException {
30 |
31 | String book_ISBN = request.getParameter("ISBN");
32 |
33 | JSONObject json = new JSONObject();
34 | if (StringUtils.validateEmpty(book_ISBN)) {
35 |
36 | Borrow borrow = ServiceFactory.getIBorrowServiceInstance().selectByISBN(book_ISBN);
37 | json.put("data", borrow);
38 | json.put("code", "000000");
39 | json.put("message", "请求成功");
40 | response.getWriter().println(json);
41 |
42 | } else {
43 | json.put("code", "111111");
44 | json.put("message", "缺少参数!");
45 | response.getWriter().println(json);
46 | }
47 | }
48 |
49 | }
50 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/borrow/ReturnBookServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.borrow;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | import com.book.service.ServiceFactory;
11 | import com.book.util.StringUtils;
12 |
13 | import cn.hutool.json.JSONObject;
14 |
15 | /**
16 | * 归还图书
17 | */
18 | public class ReturnBookServlet extends HttpServlet {
19 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
20 | throws ServletException, IOException {
21 | doPost(request, response);
22 | }
23 |
24 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
25 | throws ServletException, IOException {
26 | String ISBN = request.getParameter("ISBN");
27 | String borrow_date = request.getParameter("return_date");
28 | JSONObject json = new JSONObject();
29 | if (!StringUtils.validateEmpty(ISBN)) {
30 | json.put("code", "111111");
31 | json.put("message", "请输入书籍编号");
32 | response.getWriter().println(json);
33 | return;
34 | }
35 | boolean result = ServiceFactory.getIBookServiceInstance().returnBookStatus(ISBN, borrow_date);
36 | if (result) {
37 | json.put("code", "000000");
38 | json.put("message", "归还成功");
39 | response.getWriter().println(json);
40 | } else {
41 | json.put("code", "111111");
42 | json.put("message", "归还失败");
43 | response.getWriter().println(json);
44 | }
45 | }
46 |
47 | }
48 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/book/DeleteBookServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.book;
2 |
3 | import java.io.IOException;
4 | import java.util.List;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | import com.book.entity.Book;
12 | import com.book.service.ServiceFactory;
13 | import com.book.util.StringUtils;
14 |
15 | import cn.hutool.json.JSONObject;
16 |
17 | /**
18 | * Servlet implementation class BookServlet
19 | */
20 | public class DeleteBookServlet extends HttpServlet {
21 |
22 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
23 | throws ServletException, IOException {
24 | doPost(request, response);
25 | }
26 |
27 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
28 | throws ServletException, IOException {
29 | String ISBN = request.getParameter("ISBN");
30 | JSONObject json = new JSONObject();
31 | if(!StringUtils.validateEmpty(ISBN))
32 | {
33 | json.put("code", "111111");
34 | json.put("message", "请输入书籍编号");
35 | response.getWriter().println(json);
36 | return;
37 | }
38 | int result = ServiceFactory.getIBookServiceInstance().deleteByISBN(ISBN);
39 | if(result == 1)
40 | {
41 | json.put("code", "000000");
42 | json.put("message", "删除成功");
43 | response.getWriter().println(json);
44 | }else {
45 | json.put("code", "111111");
46 | json.put("message", "删除失败");
47 | response.getWriter().println(json);
48 | }
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/.idea/dataSources.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | mysql.8
6 | true
7 | 本地数据库
8 | com.mysql.cj.jdbc.Driver
9 | jdbc:mysql://localhost:3306/
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | mysql.8
21 | true
22 | com.mysql.cj.jdbc.Driver
23 | jdbc:mysql://localhost:3306/mysql
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/user/StudentLoginServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.user;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | import com.book.service.ServiceFactory;
11 | import com.book.util.StringUtils;
12 |
13 | import cn.hutool.json.JSONArray;
14 | import cn.hutool.json.JSONObject;
15 |
16 | public class StudentLoginServlet extends HttpServlet {
17 |
18 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
19 | throws ServletException, IOException {
20 | doPost(request, response);
21 | }
22 |
23 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
24 | throws ServletException, IOException {
25 | String id = request.getParameter("id");
26 | String password = request.getParameter("password");
27 | JSONObject json = new JSONObject();
28 |
29 | if (StringUtils.validateEmpty(id) && StringUtils.validateEmpty(password)) {
30 | if (ServiceFactory.getIStudentServiceInstance().login(id, password)) {
31 | JSONObject object = new JSONObject();
32 | object.put("id", id);
33 | json.put("data", object);
34 | json.put("code", "000000");
35 | json.put("message", "登录成功");
36 | request.getSession().setAttribute("isLogin", "true");
37 | response.getWriter().println(json);
38 | } else {
39 | json.put("code", "111111");
40 | json.put("message", "学生ID号或密码错误!");
41 | response.getWriter().println(json);
42 | }
43 | } else {
44 | json.put("code", "111111");
45 | json.put("message", "请输入学生ID号或密码!");
46 | response.getWriter().println(json);
47 | }
48 | }
49 |
50 | }
51 |
--------------------------------------------------------------------------------
/target/m2e-wtp/web-resources/META-INF/maven/com.zhou/books/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.zhou
5 | books
6 | 0.0.1-SNAPSHOT
7 | war
8 |
9 |
10 |
11 | javax.servlet.jsp
12 | jsp-api
13 | 2.1
14 |
15 |
16 |
17 |
18 | javax.servlet
19 | javax.servlet-api
20 | 4.0.1
21 |
22 |
23 |
24 |
25 | mysql
26 | mysql-connector-java
27 | 8.0.15
28 |
29 |
30 |
31 | junit
32 | junit
33 | 4.12
34 | test
35 |
36 |
37 |
38 | commons-fileupload
39 | commons-fileupload
40 | 1.3.1
41 |
42 |
43 | commons-io
44 | commons-io
45 | 2.2
46 |
47 |
48 |
49 | cn.hutool
50 | hutool-all
51 | 4.1.19
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/user/ManagerLoginServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.user;
2 |
3 | import java.io.IOException;
4 | import javax.servlet.ServletException;
5 | import javax.servlet.http.HttpServlet;
6 | import javax.servlet.http.HttpServletRequest;
7 | import javax.servlet.http.HttpServletResponse;
8 |
9 | import com.book.service.ServiceFactory;
10 | import com.book.util.StringUtils;
11 |
12 | import cn.hutool.json.JSONObject;
13 |
14 | /**
15 | * Servlet implementation class ManagerServlet
16 | */
17 | public class ManagerLoginServlet extends HttpServlet {
18 |
19 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
20 | throws ServletException, IOException {
21 | doPost(request, response);
22 | }
23 |
24 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
25 | throws ServletException, IOException {
26 | String id = request.getParameter("id");
27 | String password = request.getParameter("password");
28 |
29 | JSONObject json = new JSONObject();
30 |
31 | if (StringUtils.validateEmpty(id) && StringUtils.validateEmpty(password)) {
32 | if (ServiceFactory.getIManagerServiceInstance().login(id, password)) {
33 | JSONObject object = new JSONObject();
34 | object.put("id", id);
35 | json.put("data", object);
36 | json.put("code", "000000");
37 | json.put("message", "登录成功");
38 | request.getSession().setAttribute("isManager", "true");
39 | response.getWriter().println(json);
40 | } else {
41 | json.put("code", "111111");
42 | json.put("message", "工作号或密码错误!");
43 | response.getWriter().println(json);
44 | }
45 | } else {
46 | json.put("code", "111111");
47 | json.put("message", "请输入工作号或密码!");
48 | response.getWriter().println(json);
49 | }
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/src/main/java/com/book/entity/Student.java:
--------------------------------------------------------------------------------
1 | package com.book.entity;
2 |
3 | /**
4 | * 数据模型(与数据库中表映射)
5 | *
6 | * @author zhouhang
7 | * @date 2019/05/14
8 | */
9 | public class Student {
10 |
11 | private String id;
12 | private String name;
13 | private String password;
14 | private int age;
15 | private String profession;
16 | private String grade;
17 | private String sex;
18 | private int integrity;
19 | private int cumulative;
20 |
21 | public String getId() {
22 | return id;
23 | }
24 |
25 | public void setId(String id) {
26 | this.id = id;
27 | }
28 |
29 | public String getName() {
30 | return name;
31 | }
32 |
33 | public void setName(String name) {
34 | this.name = name;
35 | }
36 |
37 | public String getPassword() {
38 | return password;
39 | }
40 |
41 | public void setPassword(String password) {
42 | this.password = password;
43 | }
44 |
45 | public int getAge() {
46 | return age;
47 | }
48 |
49 | public void setAge(int age) {
50 | this.age = age;
51 | }
52 |
53 | public String getProfession() {
54 | return profession;
55 | }
56 |
57 | public void setProfession(String profession) {
58 | this.profession = profession;
59 | }
60 |
61 | public String getGrade() {
62 | return grade;
63 | }
64 |
65 | public void setGrade(String grade) {
66 | this.grade = grade;
67 | }
68 |
69 | public String getSex() {
70 | return sex;
71 | }
72 |
73 | public void setSex(String sex) {
74 | this.sex = sex;
75 | }
76 |
77 | public int getIntegrity() {
78 | return integrity;
79 | }
80 |
81 | public void setIntegrity(int integrity) {
82 | this.integrity = integrity;
83 | }
84 |
85 | public int getCumulative() {
86 | return cumulative;
87 | }
88 |
89 | public void setCumulative(int cumulative) {
90 | this.cumulative = cumulative;
91 | }
92 |
93 | }
94 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/booksort/AddBookSortServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.booksort;
2 |
3 | import java.io.IOException;
4 | import java.math.BigDecimal;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | import com.book.entity.Book;
12 | import com.book.entity.BookSort;
13 | import com.book.service.ServiceFactory;
14 | import com.book.util.StringUtils;
15 |
16 | import cn.hutool.json.JSONObject;
17 |
18 | /**
19 | * Servlet implementation class BookServlet
20 | */
21 | public class AddBookSortServlet extends HttpServlet {
22 |
23 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
24 | throws ServletException, IOException {
25 | doPost(request, response);
26 | }
27 |
28 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
29 | throws ServletException, IOException {
30 |
31 | String sort_name = request.getParameter("sort_name");
32 |
33 | JSONObject json = new JSONObject();
34 | if (StringUtils.validateEmpty(sort_name)) {
35 |
36 | BookSort b = new BookSort();
37 | b.setSort_name(sort_name);
38 |
39 | int result = ServiceFactory.getIBookSortServiceInstance().insert(b);
40 | if (result == -1) {
41 | json.put("code", "222222");
42 | json.put("message", "该分类名称已存在");
43 | } else if (result == 0) {
44 | json.put("code", "111111");
45 | json.put("message", "添加图书分类失败");
46 | } else {
47 | json.put("code", "000000");
48 | json.put("message", "添加图书分类成功");
49 | }
50 | response.getWriter().println(json);
51 |
52 | } else {
53 | json.put("code", "111111");
54 | json.put("message", "缺少参数!");
55 | response.getWriter().println(json);
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/book/BorrowBookServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.book;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | import com.book.service.ServiceFactory;
11 | import com.book.util.StringUtils;
12 |
13 | import cn.hutool.json.JSONObject;
14 |
15 | /**
16 | * 借阅图书
17 | */
18 | public class BorrowBookServlet extends HttpServlet {
19 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
20 | doPost(request, response);
21 | }
22 |
23 | protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
24 | String ISBN = request.getParameter("ISBN");
25 | String s_id = request.getParameter("id");
26 | String borrow_date = request.getParameter("borrow_date");
27 | String expect_return_date = request.getParameter("expect_return_date");
28 | JSONObject json = new JSONObject();
29 | if(!StringUtils.validateEmpty(ISBN))
30 | {
31 | json.put("code", "111111");
32 | json.put("message", "请输入书籍编号");
33 | response.getWriter().println(json);
34 | return;
35 | }
36 | if(!StringUtils.validateEmpty(expect_return_date))
37 | {
38 | json.put("code", "111111");
39 | json.put("message", "请输入归还日期");
40 | response.getWriter().println(json);
41 | return;
42 | }
43 | boolean result = ServiceFactory.getIBookServiceInstance().updateBookStatus(ISBN, s_id, borrow_date, expect_return_date);
44 | if(result)
45 | {
46 | json.put("code", "000000");
47 | json.put("message", "借阅成功");
48 | response.getWriter().println(json);
49 | }else {
50 | json.put("code", "111111");
51 | json.put("message", "借阅失败");
52 | response.getWriter().println(json);
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/src/main/java/com/book/entity/Borrow.java:
--------------------------------------------------------------------------------
1 | package com.book.entity;
2 |
3 | import java.math.BigDecimal;
4 | import java.util.Date;
5 |
6 | public class Borrow {
7 |
8 | private int id;
9 | private String ISBN;
10 | private String s_id;
11 | private BigDecimal price;
12 | private String book_name;
13 | private String borrow_date;
14 | private String expect_return_date;
15 | private String return_date;
16 | private int book_borrow;
17 |
18 | public int getId() {
19 | return id;
20 | }
21 |
22 | public void setId(int id) {
23 | this.id = id;
24 | }
25 |
26 | public String getISBN() {
27 | return ISBN;
28 | }
29 |
30 | public void setISBN(String iSBN) {
31 | ISBN = iSBN;
32 | }
33 |
34 | public String getS_id() {
35 | return s_id;
36 | }
37 |
38 | public void setS_id(String s_id) {
39 | this.s_id = s_id;
40 | }
41 |
42 | public BigDecimal getPrice() {
43 | return price;
44 | }
45 |
46 | public void setPrice(BigDecimal price) {
47 | this.price = price;
48 | }
49 |
50 | public String getBook_name() {
51 | return book_name;
52 | }
53 |
54 | public void setBook_name(String book_name) {
55 | this.book_name = book_name;
56 | }
57 |
58 | public String getBorrow_date() {
59 | return borrow_date;
60 | }
61 |
62 | public void setBorrow_date(String borrow_date) {
63 | this.borrow_date = borrow_date;
64 | }
65 |
66 | public String getExpect_return_date() {
67 | return expect_return_date;
68 | }
69 |
70 | public void setExpect_return_date(String expect_return_date) {
71 | this.expect_return_date = expect_return_date;
72 | }
73 |
74 | public String getReturn_date() {
75 | return return_date;
76 | }
77 |
78 | public void setReturn_date(String return_date) {
79 | this.return_date = return_date;
80 | }
81 |
82 | public int getBook_borrow() {
83 | return book_borrow;
84 | }
85 |
86 | public void setBook_borrow(int book_borrow) {
87 | this.book_borrow = book_borrow;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/java/com/book/entity/Book.java:
--------------------------------------------------------------------------------
1 | package com.book.entity;
2 |
3 | import java.math.BigDecimal;
4 | import java.util.Date;
5 |
6 | public class Book {
7 |
8 | private String ISBN;
9 | private String book_name;
10 | private String book_author;
11 | private String book_pub;
12 | private int book_borrow;
13 | private int sort_id;
14 | private String book_record;
15 | private BigDecimal book_price;
16 | private String sort_name;
17 |
18 | public String getISBN() {
19 | return ISBN;
20 | }
21 |
22 | public void setISBN(String iSBN) {
23 | ISBN = iSBN;
24 | }
25 |
26 | public String getBook_name() {
27 | return book_name;
28 | }
29 |
30 | public void setBook_name(String book_name) {
31 | this.book_name = book_name;
32 | }
33 |
34 | public String getBook_author() {
35 | return book_author;
36 | }
37 |
38 | public void setBook_author(String book_author) {
39 | this.book_author = book_author;
40 | }
41 |
42 | public String getBook_pub() {
43 | return book_pub;
44 | }
45 |
46 | public void setBook_pub(String book_pub) {
47 | this.book_pub = book_pub;
48 | }
49 |
50 | public int getBook_borrow() {
51 | return book_borrow;
52 | }
53 |
54 | public void setBook_borrow(int book_borrow) {
55 | this.book_borrow = book_borrow;
56 | }
57 |
58 | public int getSort_id() {
59 | return sort_id;
60 | }
61 |
62 | public void setSort_id(int sort_id) {
63 | this.sort_id = sort_id;
64 | }
65 |
66 | public String getBook_record() {
67 | return book_record;
68 | }
69 |
70 | public void setBook_record(String book_record) {
71 | this.book_record = book_record;
72 | }
73 |
74 | public BigDecimal getBook_price() {
75 | return book_price;
76 | }
77 |
78 | public void setBook_price(BigDecimal book_price) {
79 | this.book_price = book_price;
80 | }
81 |
82 | public String getSort_name() {
83 | return sort_name;
84 | }
85 |
86 | public void setSort_name(String sort_name) {
87 | this.sort_name = sort_name;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/classes/artifacts/books_war/login_manager.jsp:
--------------------------------------------------------------------------------
1 | <%@page import="com.book.util.StringUtils"%>
2 | <%@ page language="java" contentType="text/html; charset=UTF-8"
3 | pageEncoding="UTF-8"%>
4 |
5 |
6 |
7 |
8 | 图书管理系统
9 |
10 |
11 |
12 | 管理员登录页面
13 |
14 |
15 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
65 |
66 |
--------------------------------------------------------------------------------
/classes/artifacts/books_war_exploded/login_manager.jsp:
--------------------------------------------------------------------------------
1 | <%@page import="com.book.util.StringUtils"%>
2 | <%@ page language="java" contentType="text/html; charset=UTF-8"
3 | pageEncoding="UTF-8"%>
4 |
5 |
6 |
7 |
8 | 图书管理系统
9 |
10 |
11 |
12 | 管理员登录页面
13 |
14 |
15 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
65 |
66 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
3 | 4.0.0
4 | com.zhou
5 | books
6 | 0.0.1-SNAPSHOT
7 |
8 |
9 |
10 | org.apache.maven.plugins
11 | maven-compiler-plugin
12 |
13 | 6
14 | 6
15 |
16 |
17 |
18 |
19 |
20 |
21 | war
22 |
23 |
24 |
25 | javax.servlet.jsp
26 | jsp-api
27 | 2.1
28 |
29 |
30 |
31 |
32 | javax.servlet
33 | javax.servlet-api
34 | 4.0.1
35 |
36 |
37 |
38 |
39 | mysql
40 | mysql-connector-java
41 | 8.0.25
42 |
43 |
44 |
45 | junit
46 | junit
47 | 4.12
48 | test
49 |
50 |
51 |
52 | commons-fileupload
53 | commons-fileupload
54 | 1.3.1
55 |
56 |
57 | commons-io
58 | commons-io
59 | 2.2
60 |
61 |
62 |
63 | cn.hutool
64 | hutool-all
65 | 4.1.19
66 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/user/ManagerRegisterServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.user;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | import com.book.entity.Manager;
11 | import com.book.service.ServiceFactory;
12 | import com.book.util.StringUtils;
13 |
14 | import cn.hutool.json.JSONObject;
15 |
16 | public class ManagerRegisterServlet extends HttpServlet {
17 |
18 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
19 | throws ServletException, IOException {
20 | doPost(request, response);
21 | }
22 |
23 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
24 | throws ServletException, IOException {
25 | String id = request.getParameter("id");
26 | String name = request.getParameter("name");
27 | String password = request.getParameter("password");
28 | String s_age = request.getParameter("age");
29 | String phone = request.getParameter("phone");
30 |
31 | JSONObject json = new JSONObject();
32 |
33 | if (StringUtils.validateEmpty(id) && StringUtils.validateEmpty(password) && StringUtils.validateEmpty(name)
34 | && StringUtils.validateEmpty(phone)) {
35 | Manager m = new Manager();
36 |
37 | if (StringUtils.validateEmpty(s_age)) {
38 | Integer age = Integer.parseInt(s_age);
39 | m.setAge(age);
40 | }
41 | m.setId(id);
42 | m.setName(name);
43 | m.setPassword(password);
44 | m.setPhone(phone);
45 | int result = ServiceFactory.getIManagerServiceInstance().insert(m);
46 | if (result == -1) {
47 | json.put("code", "222222");
48 | json.put("message", "用户已存在");
49 | } else if (result == 0) {
50 | json.put("code", "111111");
51 | json.put("message", "注册失败");
52 | } else {
53 | json.put("code", "000000");
54 | json.put("message", "注册成功");
55 | }
56 | response.getWriter().println(json);
57 | } else {
58 | json.put("code", "111111");
59 | json.put("message", "请输入工作号、姓名、密码和电话!");
60 | response.getWriter().println(json);
61 | }
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/src/main/java/com/book/dao/BaseDao.java:
--------------------------------------------------------------------------------
1 | package com.book.dao;
2 |
3 | import java.sql.Connection;
4 | import java.sql.DriverManager;
5 | import java.sql.PreparedStatement;
6 | import java.sql.ResultSet;
7 | import java.sql.SQLException;
8 |
9 | import cn.hutool.core.lang.Console;
10 |
11 | public class BaseDao {
12 |
13 | public Connection conn;
14 | public PreparedStatement ps;
15 | public ResultSet rs;
16 |
17 | // 与数据库建立连接
18 | public boolean getConnection() {
19 | String driver = "com.mysql.cj.jdbc.Driver";
20 | String url = "jdbc:mysql://localhost:3306/library_system?serverTimezone=UTC";
21 | String user = "root";
22 | String password = "123456";
23 |
24 | try {
25 | Class.forName(driver);
26 | conn = DriverManager.getConnection(url, user, password);
27 |
28 | } catch (SQLException e) {
29 | e.printStackTrace();
30 | return false;
31 | } catch (ClassNotFoundException e) {
32 | e.printStackTrace();
33 | return false;
34 | }
35 | return true;
36 | }
37 |
38 | // 所有查询方法的模板
39 | public ResultSet selectJDBC(String sql, Object[] obj) {
40 | getConnection();
41 | try {
42 | // 使用Preparedstatement对象预编译sql
43 | ps = conn.prepareStatement(sql);
44 | for (int i = 0; i < obj.length; i++) {
45 | ps.setObject(i + 1, obj[i]);
46 | }
47 | rs = ps.executeQuery();
48 | return rs;
49 | } catch (SQLException e) {
50 | e.printStackTrace();
51 | return null;
52 | }
53 | }
54 |
55 | // 所有增删改方法的模板
56 | public int updateJDBC(String sql, Object[] obj) {
57 | getConnection();
58 | try {
59 | ps = conn.prepareStatement(sql);
60 | for (int i = 0; i < obj.length; i++) {
61 | ps.setObject(i + 1, obj[i]);
62 | }
63 | int lines = ps.executeUpdate();
64 | return lines;
65 | } catch (SQLException e) {
66 | e.printStackTrace();
67 | return 0;
68 | }
69 | }
70 |
71 | // 释放资源
72 | public boolean closeJDBC() {
73 | try {
74 | if (!rs.isClosed()) {
75 | rs.close();
76 | }
77 | if (!ps.isClosed()) {
78 | ps.close();
79 | }
80 | if (!conn.isClosed()) {
81 | conn.close();
82 | }
83 | } catch (SQLException e) {
84 | e.printStackTrace();
85 | return false;
86 | }
87 | return true;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/src/main/webapp/register_manager.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 |
7 | 管理员注册页面
8 |
9 |
10 |
11 | 管理员注册页面
12 |
18 |
19 |
20 |
21 |
22 |
23 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/test/resources/sql/library_system.sql:
--------------------------------------------------------------------------------
1 | /*
2 | SQLyog Ultimate v8.32
3 | MySQL - 8.0.15 : Database - test
4 | *********************************************************************
5 | */
6 | /* 使用说明 */
7 | /*
8 | 将以下代码放到SQLyog工具进行执行,将创建数据库和数据表
9 | * */
10 | CREATE DATABASE `library_system`;
11 | USE `library_system`;
12 |
13 | CREATE TABLE `student` (
14 | `s_id` varchar(20) NOT NULL,
15 | `name` varchar(12) NOT NULL,
16 | `password` varchar(20) NOT NULL,
17 | `age` int,
18 | `profession` varchar(20),
19 | `grade` varchar(20),
20 | `sex` char(4),
21 | `integrity` int DEFAULT 1,
22 | `cumulative` int DEFAULT 0,
23 | PRIMARY KEY (`s_id`)
24 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
25 |
26 | CREATE TABLE `manager` (
27 | `id` varchar(20) NOT NULL,
28 | `name` varchar(12) NOT NULL,
29 | `password` varchar(20) NOT NULL,
30 | `age` int,
31 | `phone` char(11) NOT NULL,
32 | PRIMARY KEY (`id`)
33 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
34 |
35 | CREATE TABLE `book_sort` (
36 | `sort_id` int NOT NULL AUTO_INCREMENT,
37 | `sort_name` varchar(20) NOT NULL,
38 | PRIMARY KEY (`sort_id`),
39 | UNIQUE KEY (`sort_name`)
40 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
41 |
42 | CREATE TABLE `book` (
43 | `ISBN` varchar(20) NOT NULL,
44 | `book_name` varchar(50) NOT NULL,
45 | `book_author` varchar(20) NOT NULL,
46 | `book_pub` varchar(50),
47 | `sort_id` int NOT NULL,
48 | `book_record` datetime,
49 | `book_price` DECIMAL NOT NULL,
50 | `book_borrow` int DEFAULT 0,
51 | PRIMARY KEY (`ISBN`),
52 | FOREIGN KEY (sort_id) REFERENCES book_sort(sort_id) ON DELETE CASCADE ON UPDATE CASCADE
53 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
54 |
55 | CREATE TABLE `borrow` (
56 | `id` INT NOT NULL AUTO_INCREMENT,
57 | `ISBN` VARCHAR(20) NOT NULL,
58 | `s_id` VARCHAR(20) NOT NULL,
59 | `price` DECIMAL NOT NULL,
60 | `book_name` VARCHAR(50) NOT NULL,
61 | `borrow_date` DATETIME NOT NULL,
62 | `expect_return_date` DATETIME NOT NULL,
63 | `return_date` DATETIME NOT NULL,
64 | `book_borrow` int(11) DEFAULT NULL,
65 | PRIMARY KEY (`id`),
66 | FOREIGN KEY (s_id) REFERENCES student(s_id) ON DELETE CASCADE ON UPDATE CASCADE,
67 | FOREIGN KEY (ISBN) REFERENCES book(ISBN) ON DELETE CASCADE ON UPDATE CASCADE
68 | ) ENGINE=INNODB DEFAULT CHARSET=utf8;
69 |
--------------------------------------------------------------------------------
/target/test-classes/sql/library_system.sql:
--------------------------------------------------------------------------------
1 | /*
2 | SQLyog Ultimate v8.32
3 | MySQL - 8.0.15 : Database - test
4 | *********************************************************************
5 | */
6 | /* 使用说明 */
7 | /*
8 | 将以下代码放到SQLyog工具进行执行,将创建数据库和数据表
9 | * */
10 | CREATE DATABASE `library_system`;
11 | USE `library_system`;
12 |
13 | CREATE TABLE `student` (
14 | `s_id` varchar(20) NOT NULL,
15 | `name` varchar(12) NOT NULL,
16 | `password` varchar(20) NOT NULL,
17 | `age` int,
18 | `profession` varchar(20),
19 | `grade` varchar(20),
20 | `sex` char(4),
21 | `integrity` int DEFAULT 1,
22 | `cumulative` int DEFAULT 0,
23 | PRIMARY KEY (`s_id`)
24 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
25 |
26 | CREATE TABLE `manager` (
27 | `id` varchar(20) NOT NULL,
28 | `name` varchar(12) NOT NULL,
29 | `password` varchar(20) NOT NULL,
30 | `age` int,
31 | `phone` char(11) NOT NULL,
32 | PRIMARY KEY (`id`)
33 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
34 |
35 | CREATE TABLE `book_sort` (
36 | `sort_id` int NOT NULL AUTO_INCREMENT,
37 | `sort_name` varchar(20) NOT NULL,
38 | PRIMARY KEY (`sort_id`),
39 | UNIQUE KEY (`sort_name`)
40 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
41 |
42 | CREATE TABLE `book` (
43 | `ISBN` varchar(20) NOT NULL,
44 | `book_name` varchar(50) NOT NULL,
45 | `book_author` varchar(20) NOT NULL,
46 | `book_pub` varchar(50),
47 | `sort_id` int NOT NULL,
48 | `book_record` datetime,
49 | `book_price` DECIMAL NOT NULL,
50 | `book_borrow` int DEFAULT 0,
51 | PRIMARY KEY (`ISBN`),
52 | FOREIGN KEY (sort_id) REFERENCES book_sort(sort_id) ON DELETE CASCADE ON UPDATE CASCADE
53 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
54 |
55 | CREATE TABLE `borrow` (
56 | `id` INT NOT NULL AUTO_INCREMENT,
57 | `ISBN` VARCHAR(20) NOT NULL,
58 | `s_id` VARCHAR(20) NOT NULL,
59 | `price` DECIMAL NOT NULL,
60 | `book_name` VARCHAR(50) NOT NULL,
61 | `borrow_date` DATETIME NOT NULL,
62 | `expect_return_date` DATETIME NOT NULL,
63 | `return_date` DATETIME NOT NULL,
64 | `book_borrow` int(11) DEFAULT NULL,
65 | PRIMARY KEY (`id`),
66 | FOREIGN KEY (s_id) REFERENCES student(s_id) ON DELETE CASCADE ON UPDATE CASCADE,
67 | FOREIGN KEY (ISBN) REFERENCES book(ISBN) ON DELETE CASCADE ON UPDATE CASCADE
68 | ) ENGINE=INNODB DEFAULT CHARSET=utf8;
69 |
--------------------------------------------------------------------------------
/books.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/classes/artifacts/books/register_manager.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 |
7 | 管理员注册页面
8 |
9 |
10 |
11 | 管理员注册页面
12 |
18 |
19 |
20 |
21 |
22 |
23 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/classes/artifacts/books_war/register_manager.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 |
7 | 管理员注册页面
8 |
9 |
10 |
11 | 管理员注册页面
12 |
18 |
19 |
20 |
21 |
22 |
23 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/classes/artifacts/books_war_exploded/register_manager.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8"%>
3 |
4 |
5 |
6 |
7 | 管理员注册页面
8 |
9 |
10 |
11 | 管理员注册页面
12 |
18 |
19 |
20 |
21 |
22 |
23 |
67 |
68 |
69 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/user/StudentRegisterServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.user;
2 |
3 | import java.io.IOException;
4 |
5 | import javax.servlet.ServletException;
6 | import javax.servlet.http.HttpServlet;
7 | import javax.servlet.http.HttpServletRequest;
8 | import javax.servlet.http.HttpServletResponse;
9 |
10 | import com.book.entity.Student;
11 | import com.book.service.ServiceFactory;
12 | import com.book.util.StringUtils;
13 |
14 | import cn.hutool.json.JSONObject;
15 |
16 | public class StudentRegisterServlet extends HttpServlet {
17 |
18 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
19 | throws ServletException, IOException {
20 | doPost(request, response);
21 | }
22 |
23 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
24 | throws ServletException, IOException {
25 | String id = request.getParameter("id");
26 | String name = request.getParameter("name");
27 | String password = request.getParameter("password");
28 | String s_age = request.getParameter("age");
29 | String sex = request.getParameter("sex");
30 | String grade = request.getParameter("grade");
31 | String profession = request.getParameter("profession");
32 |
33 | JSONObject json = new JSONObject();
34 |
35 | if (StringUtils.validateEmpty(id) && StringUtils.validateEmpty(password) && StringUtils.validateEmpty(name)) {
36 | Student stu = new Student();
37 |
38 | if (StringUtils.validateEmpty(s_age)) {
39 | Integer age = Integer.parseInt(s_age);
40 | stu.setAge(age);
41 | }
42 | stu.setGrade(grade);
43 | stu.setId(id);
44 | stu.setName(name);
45 | stu.setPassword(password);
46 | stu.setSex(sex);
47 | stu.setProfession(profession);
48 | int result = ServiceFactory.getIStudentServiceInstance().insert(stu);
49 |
50 | if (result == -1) {
51 | json.put("code", "222222");
52 | json.put("message", "用户已存在");
53 | } else if (result == 0) {
54 | json.put("code", "111111");
55 | json.put("message", "注册失败");
56 | } else {
57 | json.put("code", "000000");
58 | json.put("message", "注册成功");
59 | }
60 | response.getWriter().println(json);
61 | } else {
62 | json.put("code", "111111");
63 | json.put("message", "请输入学生ID号、姓名和密码!");
64 | response.getWriter().println(json);
65 | }
66 | }
67 |
68 | }
69 |
--------------------------------------------------------------------------------
/src/main/webapp/login.jsp:
--------------------------------------------------------------------------------
1 | <%@page import="com.book.util.StringUtils" %>
2 | <%@ page language="java" contentType="text/html; charset=UTF-8"
3 | pageEncoding="UTF-8" %>
4 |
5 |
6 |
7 |
8 | 图书管理系统
9 |
10 |
11 |
12 | 学生登录页面
13 |
14 |
15 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
67 |
68 |
--------------------------------------------------------------------------------
/classes/artifacts/books/login.jsp:
--------------------------------------------------------------------------------
1 | <%@page import="com.book.util.StringUtils" %>
2 | <%@ page language="java" contentType="text/html; charset=UTF-8"
3 | pageEncoding="UTF-8" %>
4 |
5 |
6 |
7 |
8 | 图书管理系统
9 |
10 |
11 |
12 | 学生登录页面
13 |
14 |
15 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
67 |
68 |
--------------------------------------------------------------------------------
/classes/artifacts/books_war/login.jsp:
--------------------------------------------------------------------------------
1 | <%@page import="com.book.util.StringUtils" %>
2 | <%@ page language="java" contentType="text/html; charset=UTF-8"
3 | pageEncoding="UTF-8" %>
4 |
5 |
6 |
7 |
8 | 图书管理系统
9 |
10 |
11 |
12 | 学生登录页面
13 |
14 |
15 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
67 |
68 |
--------------------------------------------------------------------------------
/classes/artifacts/books_war_exploded/login.jsp:
--------------------------------------------------------------------------------
1 | <%@page import="com.book.util.StringUtils" %>
2 | <%@ page language="java" contentType="text/html; charset=UTF-8"
3 | pageEncoding="UTF-8" %>
4 |
5 |
6 |
7 |
8 | 图书管理系统
9 |
10 |
11 |
12 | 学生登录页面
13 |
14 |
15 |
19 |
20 |
21 |
22 |
25 |
28 |
29 |
30 |
31 |
32 |
33 |
67 |
68 |
--------------------------------------------------------------------------------
/src/main/webapp/login_manager.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8" %>
3 |
4 |
5 |
6 |
7 | 图书管理系统
8 |
9 |
10 |
11 | 管理员登录页面
12 |
13 |
14 |
18 |
19 |
20 |
21 |
24 |
27 |
28 |
29 |
30 |
31 |
32 |
67 |
68 |
--------------------------------------------------------------------------------
/classes/artifacts/books/login_manager.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8" %>
3 |
4 |
5 |
6 |
7 | 图书管理系统
8 |
9 |
10 |
11 | 管理员登录页面
12 |
13 |
14 |
18 |
19 |
20 |
21 |
24 |
27 |
28 |
29 |
30 |
31 |
32 |
67 |
68 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/book/EditBookServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.book;
2 |
3 | import java.io.IOException;
4 | import java.math.BigDecimal;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | import com.book.entity.Book;
12 | import com.book.service.ServiceFactory;
13 | import com.book.util.StringUtils;
14 |
15 | import cn.hutool.json.JSONObject;
16 |
17 | /**
18 | * Servlet implementation class BookServlet
19 | */
20 | public class EditBookServlet extends HttpServlet {
21 |
22 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
23 | throws ServletException, IOException {
24 | doPost(request, response);
25 | }
26 |
27 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
28 | throws ServletException, IOException {
29 | String old_book_ISBN = request.getParameter("ISBN");
30 | String book_ISBN = request.getParameter("book_ISBN");
31 | String book_name = request.getParameter("book_name");
32 | String book_author = request.getParameter("book_author");
33 | String book_pub = request.getParameter("book_pub");
34 | String book_record = request.getParameter("book_record");
35 | String book_price = request.getParameter("book_price");
36 | String book_sort = request.getParameter("book_sort");
37 | String book_borrow = request.getParameter("book_borrow");
38 |
39 | JSONObject json = new JSONObject();
40 | if (StringUtils.validateEmpty(book_ISBN) && StringUtils.validateEmpty(book_name)
41 | && StringUtils.validateEmpty(book_name) && StringUtils.validateEmpty(book_price)) {
42 |
43 | Book b = new Book();
44 |
45 | if (StringUtils.validateEmpty(book_borrow)) {
46 | Integer borrow = Integer.parseInt(book_borrow);
47 | b.setBook_borrow(borrow);
48 | }
49 | if (StringUtils.validateEmpty(book_sort)) {
50 | Integer sort_id = Integer.parseInt(book_sort);
51 | b.setSort_id(sort_id);
52 | }
53 |
54 | b.setBook_name(book_name);
55 | b.setBook_author(book_author);
56 | b.setBook_pub(book_pub);
57 | b.setBook_record(book_record);
58 | b.setISBN(book_ISBN);
59 |
60 | BigDecimal price = new BigDecimal(book_price);
61 | // 设置小数位数,第一个变量是小数位数,第二个变量是取舍方法(四舍五入)
62 | price = price.setScale(2, BigDecimal.ROUND_HALF_UP);
63 | b.setBook_price(price);
64 |
65 | int result = ServiceFactory.getIBookServiceInstance().update(b, old_book_ISBN);
66 | if (result == 1) {
67 | json.put("code", "000000");
68 | json.put("message", "编辑成功");
69 | response.getWriter().println(json);
70 | } else {
71 | json.put("code", "111111");
72 | json.put("message", "编辑失败");
73 | response.getWriter().println(json);
74 | }
75 | } else {
76 | json.put("code", "222222");
77 | json.put("message", "缺少参数");
78 | response.getWriter().println(json);
79 | }
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/src/main/java/com/book/servlet/book/AddBookServlet.java:
--------------------------------------------------------------------------------
1 | package com.book.servlet.book;
2 |
3 | import java.io.IOException;
4 | import java.math.BigDecimal;
5 |
6 | import javax.servlet.ServletException;
7 | import javax.servlet.http.HttpServlet;
8 | import javax.servlet.http.HttpServletRequest;
9 | import javax.servlet.http.HttpServletResponse;
10 |
11 | import com.book.entity.Book;
12 | import com.book.service.ServiceFactory;
13 | import com.book.util.StringUtils;
14 |
15 | import cn.hutool.json.JSONObject;
16 |
17 | /**
18 | * Servlet implementation class BookServlet
19 | */
20 | public class AddBookServlet extends HttpServlet {
21 |
22 | protected void doGet(HttpServletRequest request, HttpServletResponse response)
23 | throws ServletException, IOException {
24 | doPost(request, response);
25 | }
26 |
27 | protected void doPost(HttpServletRequest request, HttpServletResponse response)
28 | throws ServletException, IOException {
29 |
30 | String book_ISBN = request.getParameter("book_ISBN");
31 | String book_name = request.getParameter("book_name");
32 | String book_author = request.getParameter("book_author");
33 | String book_pub = request.getParameter("book_pub");
34 | String book_record = request.getParameter("book_record");
35 | String book_price = request.getParameter("book_price");
36 | String book_sort = request.getParameter("book_sort");
37 | String book_borrow = request.getParameter("book_borrow");
38 |
39 | JSONObject json = new JSONObject();
40 | if (StringUtils.validateEmpty(book_ISBN) && StringUtils.validateEmpty(book_name)
41 | && StringUtils.validateEmpty(book_name) && StringUtils.validateEmpty(book_price)) {
42 |
43 | Book b = new Book();
44 |
45 | if (StringUtils.validateEmpty(book_borrow)) {
46 | Integer borrow = Integer.parseInt(book_borrow);
47 | b.setBook_borrow(borrow);
48 | }
49 | if (StringUtils.validateEmpty(book_sort)) {
50 | Integer sort_id = Integer.parseInt(book_sort);
51 | b.setSort_id(sort_id);
52 | }
53 |
54 | b.setBook_name(book_name);
55 | b.setBook_author(book_author);
56 | b.setBook_pub(book_pub);
57 | b.setBook_record(book_record);
58 | b.setISBN(book_ISBN);
59 |
60 | BigDecimal price = new BigDecimal(book_price);
61 | // 设置小数位数,第一个变量是小数位数,第二个变量是取舍方法(四舍五入)
62 | price = price.setScale(2, BigDecimal.ROUND_HALF_UP);
63 | b.setBook_price(price);
64 |
65 | int result = ServiceFactory.getIBookServiceInstance().insert(b);
66 | if(result == -1) {
67 | json.put("code", "222222");
68 | json.put("message", "书籍编号已存在");
69 | }
70 | else if (result == 0) {
71 | json.put("code", "111111");
72 | json.put("message", "添加图书失败");
73 | } else {
74 | json.put("code", "000000");
75 | json.put("message", "添加图书成功");
76 | }
77 | response.getWriter().println(json);
78 |
79 | } else {
80 | json.put("code", "111111");
81 | json.put("message", "缺少参数!");
82 | response.getWriter().println(json);
83 | }
84 | }
85 |
86 | }
87 |
--------------------------------------------------------------------------------
/src/main/webapp/register.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8" %>
3 |
4 |
5 |
6 |
7 | 注册页面
8 |
9 |
10 |
11 | 学生注册页面
12 |
22 |
23 |
24 |
25 |
26 |
27 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/classes/artifacts/books/register.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8" %>
3 |
4 |
5 |
6 |
7 | 注册页面
8 |
9 |
10 |
11 | 学生注册页面
12 |
22 |
23 |
24 |
25 |
26 |
27 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/classes/artifacts/books_war/register.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8" %>
3 |
4 |
5 |
6 |
7 | 注册页面
8 |
9 |
10 |
11 | 学生注册页面
12 |
22 |
23 |
24 |
25 |
26 |
27 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/classes/artifacts/books_war_exploded/register.jsp:
--------------------------------------------------------------------------------
1 | <%@ page language="java" contentType="text/html; charset=UTF-8"
2 | pageEncoding="UTF-8" %>
3 |
4 |
5 |
6 |
7 | 注册页面
8 |
9 |
10 |
11 | 学生注册页面
12 |
22 |
23 |
24 |
25 |
26 |
27 |
78 |
79 |
80 |
--------------------------------------------------------------------------------
/src/main/java/com/book/dao/impl/ManagerDaoImpl.java:
--------------------------------------------------------------------------------
1 | package com.book.dao.impl;
2 |
3 | import java.sql.ResultSet;
4 | import java.sql.SQLException;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import com.book.dao.BaseDao;
9 | import com.book.dao.IManagerDao;
10 | import com.book.entity.Manager;
11 |
12 | public class ManagerDaoImpl extends BaseDao implements IManagerDao {
13 |
14 | public boolean login(String id, String password) {
15 | String sql = "select `id`, `password` from manager where `id` = ? and `password` = ?";
16 | Object[] obj = { id, password };
17 | ResultSet rs = selectJDBC(sql, obj);
18 | try {
19 | if (rs.next()) {
20 | return true;
21 | }
22 | return false;
23 | } catch (SQLException e) {
24 | e.printStackTrace();
25 | return false;
26 | } finally {
27 | closeJDBC();
28 | }
29 | }
30 |
31 | public Manager selectById(String id) {
32 | Manager m = new Manager();
33 | String sql = "select * from manager where id = ?";
34 | Object[] obj = { id };
35 | ResultSet rs = selectJDBC(sql, obj);
36 | try {
37 | while (rs.next()) {
38 | m.setAge(rs.getInt("age"));
39 | m.setId(rs.getString("id"));
40 | m.setName(rs.getString("name"));
41 | m.setPassword(rs.getString("password"));
42 | m.setPhone(rs.getString("phone"));
43 | }
44 | return m;
45 | } catch (Exception e) {
46 | e.printStackTrace();
47 | return null;
48 | } finally {
49 | closeJDBC();
50 | }
51 | }
52 |
53 | public boolean checkIsExist(String id) {
54 | String sql = "select id from manager where id = ?";
55 | Object[] obj = { id };
56 | ResultSet rs = selectJDBC(sql, obj);
57 | try {
58 | if (rs.next()) {
59 | return true;
60 | } else {
61 | return false;
62 | }
63 | } catch (Exception e) {
64 | e.printStackTrace();
65 | return false;
66 | } finally {
67 | closeJDBC();
68 | }
69 | }
70 |
71 | public int insert(Manager m) {
72 | boolean result = checkIsExist(m.getId());
73 | if (result) {
74 | return -1;
75 | }
76 | String sql = "insert into manager (id, name, password, age, phone) values (?,?,?,?,?)";
77 | Object[] obj = { m.getId(), m.getName(), m.getPassword(), m.getAge(), m.getPhone() };
78 | int lines = updateJDBC(sql, obj);
79 | if (lines > 0) {
80 | return 1;
81 | }
82 | return 0;
83 | }
84 |
85 | public int update(Manager m, String id) {
86 | String sql = "update manager set id = ?, name = ?, password = ?, age = ?, phone = ? where id = ? ";
87 | Object[] obj = { m.getId(), m.getName(), m.getPassword(), m.getAge(), m.getPhone(), id };
88 | int lines = updateJDBC(sql, obj);
89 | if (lines > 0) {
90 | return 1;
91 | }
92 | return 0;
93 | }
94 |
95 | public List selectList() {
96 | List lists = new ArrayList();
97 | String sql = "select * from manager";
98 | Object[] obj = {};
99 | ResultSet rs = selectJDBC(sql, obj);
100 | try {
101 | while (rs.next()) {
102 |
103 | Manager m = new Manager();
104 | m.setAge(rs.getInt("age"));
105 | m.setId(rs.getString("id"));
106 | m.setName(rs.getString("name"));
107 | m.setPassword(rs.getString("password"));
108 | m.setPhone(rs.getString("phone"));
109 |
110 | lists.add(m);
111 | }
112 | return lists;
113 | } catch (SQLException e) {
114 | e.printStackTrace();
115 | return null;
116 | } finally {
117 | closeJDBC();
118 | }
119 | }
120 |
121 | public int deleteById(String id) {
122 | String sql = "delete from manager where id = ?";
123 | Object[] obj = { id };
124 | int lines = updateJDBC(sql, obj);
125 | if (lines > 0) {
126 | return 1;
127 | }
128 | return 0;
129 | }
130 |
131 | }
132 |
--------------------------------------------------------------------------------
/src/main/java/com/book/dao/impl/BookSortDaoImpl.java:
--------------------------------------------------------------------------------
1 | package com.book.dao.impl;
2 |
3 | import java.sql.ResultSet;
4 | import java.sql.SQLException;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import com.book.dao.BaseDao;
9 | import com.book.dao.IBookSortDao;
10 | import com.book.dao.IBorrowDao;
11 | import com.book.entity.Book;
12 | import com.book.entity.BookSort;
13 | import com.book.entity.Borrow;
14 | import com.book.entity.Student;
15 |
16 | public class BookSortDaoImpl extends BaseDao implements IBookSortDao {
17 |
18 | public BookSort selectById(int id) {
19 | BookSort m = new BookSort();
20 | String sql = "select * from book_sort where sort_id = ?";
21 | Object[] obj = { id };
22 | ResultSet rs = selectJDBC(sql, obj);
23 | try {
24 | while (rs.next()) {
25 | m.setId(rs.getInt("sort_id"));
26 | m.setSort_name(rs.getString("sort_name"));
27 | }
28 | return m;
29 | } catch (Exception e) {
30 | e.printStackTrace();
31 | return null;
32 | } finally {
33 | closeJDBC();
34 | }
35 | }
36 |
37 | public BookSort selectByName(String name) {
38 | BookSort m = new BookSort();
39 | String sql = "select * from book_sort where sort_name = ?";
40 | Object[] obj = { name };
41 | ResultSet rs = selectJDBC(sql, obj);
42 | try {
43 | while (rs.next()) {
44 | m.setId(rs.getInt("sort_id"));
45 | m.setSort_name(rs.getString("sort_name"));
46 | }
47 | return m;
48 | } catch (Exception e) {
49 | e.printStackTrace();
50 | return null;
51 | } finally {
52 | closeJDBC();
53 | }
54 | }
55 |
56 | public boolean checkIsExist(String name) {
57 | String sql = "select sort_name from book_sort where sort_name = ?";
58 | Object[] obj = { name };
59 | ResultSet rs = selectJDBC(sql, obj);
60 | try {
61 | if (rs.next()) {
62 | return true;
63 | } else {
64 | return false;
65 | }
66 | } catch (Exception e) {
67 | e.printStackTrace();
68 | return false;
69 | } finally {
70 | closeJDBC();
71 | }
72 | }
73 |
74 | public int insert(BookSort sort) {
75 | boolean result = checkIsExist(sort.getSort_name());
76 | if (result) {
77 | return -1;
78 | }
79 | String sql = "insert into book_sort (sort_name) values (?)";
80 | Object[] obj = { sort.getSort_name() };
81 | int lines = updateJDBC(sql, obj);
82 | if (lines > 0) {
83 | closeJDBC();
84 | return 1;
85 | }
86 | closeJDBC();
87 | return 0;
88 | }
89 |
90 | public int update(BookSort sort) {
91 | String sql = "update book_sort set sort_name = ? where sort_id = ? ";
92 | Object[] obj = { sort.getSort_name(), sort.getId() };
93 | int lines = updateJDBC(sql, obj);
94 | if (lines > 0) {
95 | closeJDBC();
96 | return 1;
97 | }
98 | closeJDBC();
99 | return 0;
100 | }
101 |
102 | public List selectList() {
103 | List lists = new ArrayList();
104 | String sql = "select * from book_sort";
105 | Object[] obj = {};
106 | ResultSet rs = selectJDBC(sql, obj);
107 | try {
108 | while (rs.next()) {
109 |
110 | BookSort stu = new BookSort();
111 | stu.setId(rs.getInt("sort_id"));
112 | stu.setSort_name(rs.getString("sort_name"));
113 |
114 | lists.add(stu);
115 | }
116 | return lists;
117 | } catch (SQLException e) {
118 | e.printStackTrace();
119 | return null;
120 | } finally {
121 | closeJDBC();
122 | }
123 | }
124 |
125 | public int deleteById(int id) {
126 | String sql = "delete from book_sort where sort_id = ?";
127 | Object[] obj = { id };
128 | int lines = updateJDBC(sql, obj);
129 | if (lines > 0) {
130 | closeJDBC();
131 | return 1;
132 | }
133 | closeJDBC();
134 | return 0;
135 | }
136 |
137 | }
138 |
--------------------------------------------------------------------------------
/src/main/java/com/book/dao/impl/StudentDaoImpl.java:
--------------------------------------------------------------------------------
1 | package com.book.dao.impl;
2 |
3 | import java.sql.ResultSet;
4 | import java.sql.SQLException;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import com.book.dao.BaseDao;
9 | import com.book.dao.IStudentDao;
10 | import com.book.entity.Student;
11 |
12 | public class StudentDaoImpl extends BaseDao implements IStudentDao {
13 |
14 | public boolean login(String id, String password) {
15 | String sql = "select `s_id`, `password` from student where `s_id` = ? and `password` = ?";
16 | Object[] obj = { id, password };
17 | ResultSet rs = selectJDBC(sql, obj);
18 | try {
19 | if (rs.next()) {
20 | return true;
21 | }
22 | return false;
23 | } catch (SQLException e) {
24 | e.printStackTrace();
25 | return false;
26 | } finally {
27 | closeJDBC();
28 | }
29 | }
30 |
31 | public Student selectById(String id) {
32 | Student stu = new Student();
33 | String sql = "select * from student where s_id = ?";
34 | Object[] obj = { id };
35 | ResultSet rs = selectJDBC(sql, obj);
36 | try {
37 | while (rs.next()) {
38 | stu.setAge(rs.getInt("age"));
39 | stu.setCumulative(rs.getInt("cumulative"));
40 | stu.setGrade(rs.getString("grade"));
41 | stu.setId(rs.getString("s_id"));
42 | stu.setIntegrity(rs.getInt("integrity"));
43 | stu.setName(rs.getString("name"));
44 | stu.setPassword(rs.getString("password"));
45 | stu.setProfession(rs.getString("profession"));
46 | stu.setSex(rs.getString("sex"));
47 | }
48 | return stu;
49 | } catch (Exception e) {
50 | e.printStackTrace();
51 | return null;
52 | } finally {
53 | closeJDBC();
54 | }
55 | }
56 |
57 | public boolean checkIsExist(String id) {
58 | String sql = "select s_id from student where s_id = ?";
59 | Object[] obj = { id };
60 | ResultSet rs = selectJDBC(sql, obj);
61 | try {
62 | if (rs.next()) {
63 | return true;
64 | } else {
65 | return false;
66 | }
67 | } catch (Exception e) {
68 | e.printStackTrace();
69 | return false;
70 | } finally {
71 | closeJDBC();
72 | }
73 | }
74 |
75 | public int insert(Student stu) {
76 | boolean result = checkIsExist(stu.getId());
77 | if (result) {
78 | return -1;
79 | }
80 | String sql = "insert into student (s_id, name, password, age, profession, grade, sex) values (?,?,?,?,?,?,?)";
81 | Object[] obj = { stu.getId(), stu.getName(), stu.getPassword(), stu.getAge(), stu.getProfession(),
82 | stu.getGrade(), stu.getSex() };
83 | int lines = updateJDBC(sql, obj);
84 | if (lines > 0) {
85 | closeJDBC();
86 | return 1;
87 | }
88 | closeJDBC();
89 | return 0;
90 | }
91 |
92 | public int update(Student stu, String s_id) {
93 | String sql = "update student set s_id = ?, name = ?, password = ?, age = ?, profession = ?, grade = ?, sex = ? where s_id = ? ";
94 | Object[] obj = { stu.getName(), stu.getPassword(), stu.getAge(), stu.getProfession(), stu.getGrade(),
95 | stu.getSex(), s_id };
96 | int lines = updateJDBC(sql, obj);
97 | if (lines > 0) {
98 | closeJDBC();
99 | return 1;
100 | }
101 | closeJDBC();
102 | return 0;
103 | }
104 |
105 | public List selectList() {
106 | List lists = new ArrayList();
107 | String sql = "select * from student";
108 | Object[] obj = {};
109 | ResultSet rs = selectJDBC(sql, obj);
110 | try {
111 | while (rs.next()) {
112 |
113 | Student stu = new Student();
114 | stu.setAge(rs.getInt("age"));
115 | stu.setCumulative(rs.getInt("cumulative"));
116 | stu.setGrade(rs.getString("grade"));
117 | stu.setId(rs.getString("s_id"));
118 | stu.setIntegrity(rs.getInt("integrity"));
119 | stu.setName(rs.getString("name"));
120 | stu.setPassword(rs.getString("password"));
121 | stu.setProfession(rs.getString("profession"));
122 | stu.setSex(rs.getString("sex"));
123 |
124 | lists.add(stu);
125 | }
126 | return lists;
127 | } catch (SQLException e) {
128 | e.printStackTrace();
129 | return null;
130 | } finally {
131 | closeJDBC();
132 | }
133 | }
134 |
135 | public int deleteById(String id) {
136 | String sql = "delete from student where s_id = ?";
137 | Object[] obj = { id };
138 | int lines = updateJDBC(sql, obj);
139 | if (lines > 0) {
140 | closeJDBC();
141 | return 1;
142 | }
143 | closeJDBC();
144 | return 0;
145 | }
146 |
147 | }
148 |
--------------------------------------------------------------------------------
/src/main/java/com/book/dao/impl/BorrowDaoImpl.java:
--------------------------------------------------------------------------------
1 | package com.book.dao.impl;
2 |
3 | import java.sql.ResultSet;
4 | import java.sql.SQLException;
5 | import java.util.ArrayList;
6 | import java.util.List;
7 |
8 | import com.book.dao.BaseDao;
9 | import com.book.dao.IBorrowDao;
10 | import com.book.entity.Borrow;
11 |
12 | public class BorrowDaoImpl extends BaseDao implements IBorrowDao {
13 |
14 | public Borrow selectByISBN(String ISBN) {
15 | Borrow m = new Borrow();
16 | String sql = "select * from borrow where ISBN = ?";
17 | Object[] obj = { ISBN };
18 | ResultSet rs = selectJDBC(sql, obj);
19 | try {
20 | while (rs.next()) {
21 | m.setId(rs.getInt("id"));
22 | m.setISBN(rs.getString("iSBN"));
23 | m.setBook_name(rs.getString("book_name"));
24 | m.setBorrow_date(rs.getString("borrow_date"));
25 | m.setExpect_return_date(rs.getString("expect_return_date"));
26 | m.setPrice(rs.getBigDecimal("price"));
27 | m.setReturn_date(rs.getString("return_date"));
28 | m.setS_id(rs.getString("s_id"));
29 | m.setBook_borrow(rs.getInt("book_borrow"));
30 | }
31 | return m;
32 | } catch (Exception e) {
33 | e.printStackTrace();
34 | return null;
35 | } finally {
36 | closeJDBC();
37 | }
38 | }
39 |
40 | public List selectByID(String id) {
41 | List lists = new ArrayList();
42 | String sql = "select * from borrow where s_id = ?";
43 | Object[] obj = { id };
44 | ResultSet rs = selectJDBC(sql, obj);
45 | try {
46 | while (rs.next()) {
47 | Borrow m = new Borrow();
48 | m.setId(rs.getInt("id"));
49 | m.setISBN(rs.getString("iSBN"));
50 | m.setBook_name(rs.getString("book_name"));
51 | m.setBorrow_date(rs.getString("borrow_date"));
52 | m.setExpect_return_date(rs.getString("expect_return_date"));
53 | m.setPrice(rs.getBigDecimal("price"));
54 | m.setReturn_date(rs.getString("return_date"));
55 | m.setS_id(rs.getString("s_id"));
56 | m.setBook_borrow(rs.getInt("book_borrow"));
57 |
58 | lists.add(m);
59 | }
60 | return lists;
61 | } catch (Exception e) {
62 | e.printStackTrace();
63 | return null;
64 | } finally {
65 | closeJDBC();
66 | }
67 | }
68 |
69 | public int insert(Borrow m) {
70 | String sql = "insert into borrow (ISBN, s_id, price, book_name, borrow_date, expect_return_date, return_date, book_borrow) values ((SELECT ISBN FROM book WHERE ISBN = ?),(SELECT s_id FROM student WHERE s_id = ?),?,?,?,?,?,?)";
71 | Object[] obj = { m.getISBN(), m.getS_id(), m.getPrice(), m.getBook_name(), m.getBorrow_date(),
72 | m.getExpect_return_date(), m.getReturn_date(), m.getBook_borrow() };
73 | int lines = updateJDBC(sql, obj);
74 | if (lines > 0) {
75 | closeJDBC();
76 | return 1;
77 | }
78 | closeJDBC();
79 | return 0;
80 | }
81 |
82 | public int update(Borrow m, String ISBN) {
83 | String sql = "update borrow set ISBN = ?, s_id = ?, price = ?, book_name = ?, borrow_date = ?, expect_return_date = ?, return_date = ?, book_borrow = ? where ISBN = ?";
84 | Object[] obj = { m.getISBN(), m.getS_id(), m.getPrice(), m.getBook_name(), m.getBorrow_date(),
85 | m.getExpect_return_date(), m.getReturn_date(), m.getBook_borrow(), ISBN };
86 | int lines = updateJDBC(sql, obj);
87 | if (lines > 0) {
88 | closeJDBC();
89 | return 1;
90 | }
91 | closeJDBC();
92 | return 0;
93 | }
94 |
95 | // 归还图书修改个别字段
96 | public int update_returnbook(Borrow m) {
97 | String sql = "update borrow set return_date = ?, book_borrow = ? where ISBN = ?";
98 | Object[] obj = { m.getReturn_date(), m.getBook_borrow(), m.getISBN() };
99 | int lines = updateJDBC(sql, obj);
100 | if (lines > 0) {
101 | closeJDBC();
102 | return 1;
103 | }
104 | closeJDBC();
105 | return 0;
106 | }
107 |
108 | public List selectList() {
109 | List lists = new ArrayList();
110 | String sql = "select * from borrow";
111 | Object[] obj = {};
112 | ResultSet rs = selectJDBC(sql, obj);
113 | try {
114 | while (rs.next()) {
115 |
116 | Borrow m = new Borrow();
117 | m.setId(rs.getInt("id"));
118 | m.setISBN(rs.getString("iSBN"));
119 | m.setBook_name(rs.getString("book_name"));
120 | m.setBorrow_date(rs.getString("borrow_date"));
121 | m.setExpect_return_date(rs.getString("expect_return_date"));
122 | m.setPrice(rs.getBigDecimal("price"));
123 | m.setReturn_date(rs.getString("return_date"));
124 | m.setS_id(rs.getString("s_id"));
125 | m.setBook_borrow(rs.getInt("book_borrow"));
126 |
127 | lists.add(m);
128 | }
129 | return lists;
130 | } catch (SQLException e) {
131 | e.printStackTrace();
132 | return null;
133 | } finally {
134 | closeJDBC();
135 | }
136 | }
137 |
138 | public int deleteByISBN(String ISBN) {
139 | String sql = "delete from borrow where ISBN = ?";
140 | Object[] obj = { ISBN };
141 | int lines = updateJDBC(sql, obj);
142 | if (lines > 0) {
143 | closeJDBC();
144 | return 1;
145 | }
146 | closeJDBC();
147 | return 0;
148 | }
149 |
150 | }
151 |
--------------------------------------------------------------------------------