Commit c7ac8552 by tzn

msg

parent 54520644
......@@ -2,6 +2,7 @@
<dictionary name="lenovo">
<words>
<w>bookarray</w>
<w>bookname</w>
<w>booktojson</w>
<w>deaed</w>
<w>fitler</w>
......
import com.example.javaproject2.Login_compare;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import static java.awt.Color.*;
//@WebServlet("/login")
public class LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
resp.setContentType("text/html");
String username = req.getParameter("username");
String password = req.getParameter("password");
PrintWriter out = resp.getWriter();
if (username.equals("")) {
out.println("<h1>登陆失败!用户名为空!</h1>");
} else if (password.equals("")) {
out.println("<h1>登陆失败!密码为空!<h1>");
} else {
out.println(Login_compare.compare(username,password));
switch(Login_compare.compare(username,password)){
case 1:
out.println("<h1>用户名或密码错误</h1>");
break;
case 2:
out.println("<h1>登陆成功!!</h1>");
resp.sendRedirect("menu.jsp");
break;
}
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
doGet(req, resp);
}
}
\ No newline at end of file
//import com.example.javaproject2.Login_compare;
//
//import javax.servlet.ServletException;
//import javax.servlet.annotation.WebServlet;
//import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.util.Iterator;
//
//import static java.awt.Color.*;
//
////@WebServlet("/login")
//public class LoginServlet extends HttpServlet {
//
// @Override
// protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// req.setCharacterEncoding("utf-8");
// resp.setCharacterEncoding("utf-8");
// resp.setContentType("text/html");
// String username = req.getParameter("username");
// String password = req.getParameter("password");
// PrintWriter out = resp.getWriter();
//
// if (username.equals("")) {
// out.println("<h1>登陆失败!用户名为空!</h1>");
// } else if (password.equals("")) {
// out.println("<h1>登陆失败!密码为空!<h1>");
// } else {
// out.println(Login_compare.compare(username,password));
// switch(Login_compare.compare(username,password)){
// case 1:
// out.println("<h1>用户名或密码错误</h1>");
// break;
// case 2:
// out.println("<h1>登陆成功!!</h1>");
// resp.sendRedirect("menu.jsp");
// break;
// }
// }
// }
// @Override
// protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// doGet(req, resp);
// }
//
//}
\ No newline at end of file
......@@ -2,4 +2,15 @@ package com.Dao;
public class AllToArray {
// int uuid;
//
// public int getUuid() {
// return uuid;
// }
//
// public void setUuid(int uuid) {
// this.uuid = uuid;
// }
}
package com.Dao;
import java.sql.*;
import java.util.ArrayList;
public class Books {
......@@ -16,177 +16,6 @@ public class Books {
String image;
int borrow_times;
/**
* 返回一个按借阅次数排列的书籍集合
* @param books_array
*/
public static void book_top_array(ArrayList<Books> books_array){
books_array.clear();
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Connecting to database...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
System.out.println("Creating statement book...");
stmt = conn.createStatement();
String sql = "SELECT * FROM books order by borrow_times desc";
ResultSet rs = stmt.executeQuery(sql);
conn.setAutoCommit(false);
while (rs.next()) {
String id = rs.getString("id");
int jdid = rs.getInt("jdid");
int bookshelf_id= rs.getInt("bookshelf_id");
int borrow_times = rs.getInt("borrow_times");
String book_name = rs.getString("book_name");
String category = rs.getString("category");
String author = rs.getString("author");
String publisher = rs.getString("publisher");
String image = rs.getString("image");
int books_same_id = rs.getInt("book_same_id");
Books.book_to_arr(id,jdid,bookshelf_id,book_name,books_same_id,category,author,publisher,image, borrow_times, books_array);
}
conn.commit();
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try
}
/**
* 返回一个按数据库顺序排列的书籍集合
* @param books_array
*/
public static void books_to_array(ArrayList<Books> books_array){
books_array.clear();
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Connecting to database top...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT * FROM books ";
ResultSet rs = stmt.executeQuery(sql);
conn.setAutoCommit(false);
while (rs.next()) {
String id = rs.getString("id");
int jdid = rs.getInt("jdid");
int bookshelf_id= rs.getInt("bookshelf_id");
int borrow_times = rs.getInt("borrow_times");
String book_name = rs.getString("book_name");
String category = rs.getString("category");
String author = rs.getString("author");
String publisher = rs.getString("publisher");
String image = rs.getString("image");
int books_same_id = rs.getInt("book_same_id");
Books.book_to_arr(id,jdid,bookshelf_id,book_name,books_same_id,category,author,publisher,image, borrow_times, books_array);
}
conn.commit();
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try
}
public static void book_to_arr(String id, int jdid, int bookshelf_id,
String book_name, int book_same_id,
String category, String author,
String publisher, String image,
int borrow_times, ArrayList<Books> books_array){
Books books = new Books();
books.id = id;
books.author = author;
books.jdid = jdid;
books.bookshelf_id = bookshelf_id;
books.book_name = book_name;
books.book_same_id = book_same_id;
books.category = category;
books.publisher = publisher;
books.image = image;
books.borrow_times = borrow_times;
books_array.add(books);
}
public int getJdid() {
......@@ -213,8 +42,6 @@ public class Books {
this.book_name = book_name;
}
public String getCategory() {
return category;
}
......
......@@ -16,94 +16,7 @@ public class Borrow {
int is_return;
int already_remind;
public static void borrow_to_array(ArrayList<Borrow> borrow_array){
borrow_array.clear();
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Connecting to database...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT * FROM borrow ";
ResultSet rs = stmt.executeQuery(sql);
conn.setAutoCommit(false);
while (rs.next()) {
String user_id = rs.getString("user_id");
String borrow_id = rs.getString("borrow_id");
String manage_id = rs.getString("manage_id");
String book_id = rs.getString("book_id");
String username = rs.getString("username");
String book_name = rs.getString("book_name");
String borrow_time = rs.getString("borrow_time");
int is_return = rs.getInt("is_return");
int already_remind = rs.getInt("already_remind");
Borrow.borrow_to_arr(user_id,borrow_id,manage_id,book_id,username,book_name,borrow_time,is_return,already_remind,borrow_array);
}
conn.commit();
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try id,user_uuid,borrow_uuid,manage_uuid,book_uuid,username,book_name,borrow_time,is_return
}
public static void borrow_to_arr(String user_id, String borrow_id,
String manage_id, String book_id,
String username,String book_name,String borrow_time,
int is_return,int already_remind,ArrayList<Borrow> borrow_array){
Borrow borrow = new Borrow();
borrow.borrow_id = borrow_id;
borrow.username = username;
borrow.user_id = user_id;
borrow.book_name = book_name;
borrow.book_id = book_id;
borrow.manage_id = manage_id;
borrow.borrow_time = borrow_time;
borrow.is_return = is_return;
borrow.already_remind = already_remind;
borrow_array.add(borrow);
}
......
package com.Dao;
public class ReturnBook {
}
......@@ -8,10 +8,28 @@ public class Return_before {
private String manage_id;
private String book_id;
private String book_name;
private String user_name;
private String borrow_time;
private int jdid;
private int bookshelf_id;
private int book_same_id;
private String return_time;
public String getReturn_time() {
return return_time;
}
public void setReturn_time(String return_time) {
this.return_time = return_time;
}
public String getUser_name() {
return user_name;
}
public void setUser_name(String user_name) {
this.user_name = user_name;
}
public String getUser_id() {
return user_id;
......
......@@ -14,85 +14,6 @@ public class User {
String phone_number;
String qq_mail;
public static void user_to_array(ArrayList<User> user_array){
user_array.clear();
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Connecting to database...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
System.out.println("Creating statement user...");
stmt = conn.createStatement();
String sql = "SELECT * FROM user ";
ResultSet rs = stmt.executeQuery(sql);
conn.setAutoCommit(false);
while (rs.next()) {
// int id, int borrowing_books, String user_uuid,String student_id,String user_password, String phone_number,String qq_mail
int borrowing_books = rs.getInt("borrowing_books");
String user_id = rs.getString("user_id");
String student_id = rs.getString("student_id");
String user_password = rs.getString("user_password");
String phone_number = rs.getString("phone_number");
String username = rs.getString("username");
String qq_mail = rs.getString("qq_mail");
User.user_to_arr(borrowing_books,user_id,username,student_id,user_password,phone_number,qq_mail,user_array);
}
conn.commit();
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try
}
public static void user_to_arr(int borrowing_books, String user_id,String username,
String student_id,String user_password,
String phone_number,String qq_mail,ArrayList<User> user_array){
User user = new User();
user.borrowing_books= borrowing_books;
user.user_id = user_id;
user.username = username;
user.student_id= student_id;
user.user_password = user_password;
user.phone_number = phone_number;
user.qq_mail = qq_mail;
user_array.add(user);
}
public int getBorrowing_books() {
......
......@@ -18,6 +18,8 @@ public class OriginFitlerTwice implements javax.servlet.Filter{
@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
System.out.println("88888ppppppp");
HttpServletResponse response = (HttpServletResponse) res;
response.setHeader("Access-Control-Allow-Origin", "*");
response.setHeader("Access-Control-Allow-Methods", "*");
......
package com.Service.Manage;
import com.Dao.Books;
import com.Service.Tool.GenerateUuid;
import com.pojo.BooksSql;
public class AddBook {
public static void add_book(String jdid, String bookshelf_id,
String book_name, String category, String author,
String publisher, String image){
Books book = new Books();
book.setJdid(Integer.parseInt(jdid));
book.setBookshelf_id(Integer.parseInt(bookshelf_id));
book.setBook_name(book_name);
book.setCategory(category);
book.setAuthor(author);
book.setPublisher(publisher);
book.setImage(image);
book.setBorrow_times(0);
book.setBook_same_id(42);
book.setId(GenerateUuid.create_uuid());
BooksSql.add_book(book);
}
}
package com.Service.Manage;
import com.pojo.BooksSql;
public class DeleteBook {
public static void delete_book(String book_id){
BooksSql.delete_book(book_id);
}
}
package com.Service.Manage;
import com.Dao.Books;
import com.pojo.BooksSql;
public class FixBook {
public static void fix_book(String book_id,String jdid, String bookshelf_id,
String book_name, String category, String author,
String publisher, String image){
Books book = new Books();
book.setId(book_id);
book.setJdid(Integer.parseInt(jdid));
book.setBookshelf_id(Integer.parseInt(bookshelf_id));
book.setBook_name(book_name);
book.setCategory(category);
book.setAuthor(author);
book.setPublisher(publisher);
book.setImage(image);
BooksSql.fix_book(book);
}
}
package com.Service.Manage;
import com.Dao.Books;
import com.Dao.User;
import com.pojo.BooksSql;
import com.pojo.BorrowSql;
import com.pojo.UserSql;
import java.util.ArrayList;
public class IsReturn {
public static void IsReturn(String borrow_id,int is_return){
BorrowSql.change_is_return(borrow_id,is_return);
}
public static void IsReturn(String book_id,String user_id,int is_return){
ArrayList<Books> book_array = new ArrayList<>();
BooksSql.books_to_array(book_array);
ArrayList<User> user_array = new ArrayList<>();
UserSql.user_to_array(user_array);
for (Books temp:book_array
) {
if (temp.getId().equals(book_id)){
for (User temp2:user_array
) {
if (temp2.getUser_id().equals(user_id)) {
BorrowSql.add_borrow(temp,temp2,is_return);
}
}
}
}
}
}
package com.Service.Manage;
import com.Dao.Books;
import com.Dao.Borrow;
import com.Dao.Return_before;
import com.Dao.User;
import com.pojo.BooksSql;
import com.pojo.BorrowSql;
import com.pojo.UserSql;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class PrintBorrowed {
/**
* 打印申请记录
* @param print_borrowed
*/
public static void print_require(ArrayList<Return_before> print_borrowed,int choose) {
ArrayList<Borrow> borrow_array = new ArrayList();
BorrowSql.borrow_to_array(borrow_array);
// System.out.println(borrow_array.size());
ArrayList<Books> book_array = new ArrayList<>();
BooksSql.book_top_array(book_array);
ArrayList<User> user_array = new ArrayList<>();
UserSql.user_to_array(user_array);
for (Borrow temp : borrow_array
) {
// System.out.println(temp.getBook_name());
//
// System.out.println(borrow_array.size());
System.out.println(temp.getIs_return());
if (temp.getIs_return() == choose) {
// System.out.println(":4444");
Return_before a = new Return_before();
a.setUser_id(temp.getUser_id());
a.setBorrow_id(temp.getBorrow_id());
a.setManage_id(temp.getManage_id());
a.setBook_id(temp.getBook_id());
a.setBook_name(temp.getBook_name());
a.setBorrow_time(temp.getBorrow_time());
for (Books temp2 : book_array
) {
if (temp2.getId().equals(temp.getBook_id())) {
a.setJdid(temp2.getJdid());
a.setBookshelf_id(temp2.getBookshelf_id());
a.setBook_same_id(temp2.getBook_same_id());
print_borrowed.add(a);
for (User temp3: user_array
) {
if(temp3.getUser_id().equals(temp.getUser_id()))
a.setUser_name(temp3.getUsername());
a.setReturn_time(String.valueOf(new Date()));
// System.out.println(a.getReturn_time());
}
}
}
}
// System.out.println("555");
}
}
/**
* 打印历史借阅记录
* @param print_borrowed
*/
public static void print_borrowed(ArrayList<Return_before> print_borrowed){
ArrayList<Borrow> borrow_array = new ArrayList();
BorrowSql.borrow_to_array(borrow_array);
for (Borrow temp:borrow_array
) {
if (temp.getIs_return() == 1) {
ArrayList<Books> book_array = new ArrayList<>();
BooksSql.book_top_array(book_array);
Return_before a = new Return_before();
a.setUser_id(temp.getUser_id());
a.setBorrow_id(temp.getBorrow_id());
a.setManage_id(temp.getManage_id());
a.setBook_id(temp.getBook_id());
a.setBook_name(temp.getBook_name());
a.setBorrow_time(temp.getBorrow_time());
for (Books temp2 : book_array
) {
ArrayList<User> user_array = new ArrayList<>();
UserSql.user_to_array(user_array);
if (temp2.getId().equals(temp.getBook_id())) {
a.setJdid(temp2.getJdid());
a.setBookshelf_id(temp2.getBookshelf_id());
a.setBook_same_id(temp2.getBook_same_id());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
a.setReturn_time(df.format(new Date()));
for (User temp3 : user_array
) {
if (temp3.getUser_id().equals(temp.getUser_id()))
a.setUser_name(temp3.getUsername());
print_borrowed.add(a);
}
}
}
}
}
}
}
package com.Service;
import com.Dao.Books;
import com.Dao.Borrow;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import static com.Service.Timeout_prompt.getTime;
public class Time_out {
public static void time_out(String user_id, ArrayList<Borrow> timeout) {
ArrayList<Borrow> borrows_array = new ArrayList<>();
Borrow.borrow_to_array(borrows_array);
for (Borrow temp : borrows_array
) {
if (temp.getUser_id().equals(user_id)) {
String[] str = temp.getBorrow_time().split("-");
Date time1 = getTime(str, 7);
System.out.println("指定时间time=" + time1);
int compareTo = time1.compareTo(new Date());
System.out.println("5464896556");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
if (compareTo < 0) {
timeout.add(temp);
}
}
}
}
}
package com.Service;
import com.Service.User.TimeOut.TimeOutPrompt;
import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
......@@ -35,7 +37,7 @@ public class Timing extends Timer {
@Override
public void run() {
Timeout_prompt.Time_check();//执行代码
TimeOutPrompt.Time_check();//执行代码
}
},date,PERIOD_DAY);
......
package com.Service;
package com.Service.Tool;
import java.util.UUID;
public class Generate_uuid {
public class GenerateUuid {
/**
*
......
package com.Service;
package com.Service.Tool;
import java.util.Properties;
......@@ -17,7 +17,7 @@ import org.springframework.mail.javamail.JavaMailSenderImpl;
/**
* 使用QQ发送邮件工具类
*/
public class QQ_mail {
public class QQMail {
private final static String SERVICE_HOST = "smtp.qq.com";//QQ服务器
private final static int PORT = 465; //smtp的端口号
......
package com.Service.User.TimeOut;
import com.Dao.Books;
import com.pojo.BooksSql;
import java.util.ArrayList;
public class Judge {
public static void judge_kind(String choose, ArrayList<Books> require){
BooksSql.guide(choose,require);
}
}
package com.Service.User.TimeOut;
import com.Dao.Books;
import com.pojo.BooksSql;
import java.util.ArrayList;
public class PrintBook {
/**
* 返回一个榜单书籍的集合
* @param book_array
*/
public static void search_all(ArrayList<Books> book_array){
ArrayList<Books> books = new ArrayList<>();
BooksSql.book_top_array(books);
int index = 0;
for (Books books_temp:books
) {
book_array.add(books_temp);
}
}
}
package com.Service.User.TimeOut;
import com.Dao.Books;
import com.Dao.Borrow;
import com.Dao.Return_before;
import com.Dao.User;
import com.alibaba.fastjson.JSON;
import com.pojo.BooksSql;
import com.pojo.BorrowSql;
import com.pojo.UserSql;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import static com.Service.User.TimeOut.TimeOutPrompt.getTime;
public class TimeOut {
public static void time_out(String user_id, ArrayList<Return_before> return_t) {
ArrayList<Borrow> borrows_array = new ArrayList<>();
BorrowSql.borrow_to_array(borrows_array);
ArrayList<Books> book_array = new ArrayList<>();
BooksSql.book_top_array(book_array);
for (Borrow temp : borrows_array
) {
if (temp.getUser_id().equals(user_id)) {
String[] str = temp.getBorrow_time().split("-");
Date time1 = getTime(str, 7);
System.out.println("指定时间time=" + time1);
int compareTo = time1.compareTo(new Date());
System.out.println("5464896556");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
// Date time5 = new Date();
if (compareTo > 0) {
Return_before a = new Return_before();
a.setUser_id(temp.getUser_id());
a.setBorrow_id(temp.getBorrow_id());
a.setManage_id(temp.getManage_id());
a.setBook_id(temp.getBook_id());
a.setBook_name(temp.getBook_name());
a.setBorrow_time(temp.getBorrow_time());
for (Books temp2 : book_array
) {
//
if (temp2.getId().equals(temp.getBook_id())) {
a.setJdid(temp2.getJdid());
a.setBookshelf_id(temp2.getBookshelf_id());
a.setBook_same_id(temp2.getBook_same_id());
return_t.add(a);
}
}
}
}
}
String json = JSON.toJSONString(return_t);
// PrintWriter out = response.getWriter();
System.out.println(json);
}
public static void all_time_out(ArrayList<Return_before> return_t) {
ArrayList<Borrow> borrows_array = new ArrayList<>();
BorrowSql.borrow_to_array(borrows_array);
ArrayList<Books> book_array = new ArrayList<>();
BooksSql.book_top_array(book_array);
for (Borrow temp : borrows_array
) {
if (temp.getIs_return() == 0) {
String[] str = temp.getBorrow_time().split("-");
Date time1 = getTime(str, 7);
System.out.println("指定时间time=" + time1);
int compareTo = time1.compareTo(new Date());
System.out.println("5464896556");
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
// Date time5 = new Date();
if (compareTo > 0) {
Return_before a = new Return_before();
a.setUser_id(temp.getUser_id());
a.setBorrow_id(temp.getBorrow_id());
a.setManage_id(temp.getManage_id());
a.setBook_id(temp.getBook_id());
a.setBook_name(temp.getBook_name());
a.setBorrow_time(temp.getBorrow_time());
for (Books temp2 : book_array
) {
if (temp2.getId().equals(temp.getBook_id())) {
a.setJdid(temp2.getJdid());
a.setBookshelf_id(temp2.getBookshelf_id());
a.setBook_same_id(temp2.getBook_same_id());
return_t.add(a);
ArrayList<User> user_array = new ArrayList<>();
UserSql.user_to_array(user_array);
for (User temp3: user_array
) {
if(temp3.getUser_id().equals(temp.getUser_id()))
a.setUser_name(temp3.getUsername());
a.setReturn_time(String.valueOf(new Date()));
// System.out.println(a.getReturn_time());
}
}
}
}
}
}
}
}
package com.Service;
package com.Service.User.TimeOut;
import com.Dao.Borrow;
import com.pojo.BorrowSql;
import java.text.SimpleDateFormat;
import java.util.*;
public class Timeout_prompt{
public class TimeOutPrompt {
static Timer timer;
static String user_id;
......@@ -14,7 +15,7 @@ public class Timeout_prompt{
public static void Time_check(){
ArrayList<Borrow> borrow_array = new ArrayList<>();
Borrow.borrow_to_array(borrow_array);
BorrowSql.borrow_to_array(borrow_array);
for (Borrow borrow:borrow_array
) {
......@@ -26,26 +27,26 @@ public class Timeout_prompt{
Date time1 = getTime(str,7);
System.out.println("指定时间time=" + time1);
// System.out.println("指定时间time=" + time1);
int compareTo = time1.compareTo(new Date());
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
if(compareTo < 0){
Timer_task_remind a = new Timer_task_remind();
TimerTaskRemind a = new TimerTaskRemind();
a.run(borrow.getUser_id(),borrow.getBorrow_time(),borrow.getBook_name());
}
Date time = getTime(str,5);
System.out.println("指定时间time=" + time);
// System.out.println("指定时间time=" + time);
int compareTo2 = time1.compareTo(new Date());
if(compareTo2 < 0){
Timer_task_warn a = new Timer_task_warn();
TimerTaskWarn a = new TimerTaskWarn();
a.run(borrow.getUser_id(),borrow.getBorrow_time(),borrow.getBook_name());
}
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
System.out.println(compareTo);
// System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
//
// System.out.println(compareTo);
}
}
......@@ -74,23 +75,12 @@ public class Timeout_prompt{
calendar.set(Calendar.DAY_OF_MONTH,Integer.parseInt(str[2])+7);
break;
}
// calendar.set(Calendar.HOUR_OF_DAY,Integer.parseInt(str[3]));
// calendar.set(Calendar.MINUTE, Integer.parseInt(str[4]));
// calendar.set(Calendar.SECOND, str[5]);
Date time = calendar.getTime();
return time;
}
// public static void main(String[] args) {
// Time_check();
// }
}
package com.Service;
package com.Service.User.TimeOut;
import com.Dao.User;
import com.Service.Tool.QQMail;
import com.pojo.UserSql;
import java.util.ArrayList;
import java.util.TimerTask;
public class Timer_task_remind {
public class TimerTaskRemind {
public void run(String user_uuid, String borrow_time, String book_name){
ArrayList<User> user_array = new ArrayList<>();
User.user_to_array(user_array);
System.out.println("已超时!!\n");
UserSql.user_to_array(user_array);
// System.out.println("已超时!!\n");
for (User user:user_array
) {
if(user.getUser_id().equals(user_uuid)){
QQ_mail.send_qq_mail("705054686@qq.com",user.getUsername(),borrow_time,
QQMail.send_qq_mail("705054686@qq.com",user.getUsername(),borrow_time,
book_name,"2022/2/25","18835963470");
}
......
package com.Service;
package com.Service.User.TimeOut;
import java.util.TimerTask;
public class Timer_task_warn {
public class TimerTaskWarn {
......
package com.Service;
package com.Service.User.TimeOut;
import com.Dao.Books;
import com.Dao.Borrow;
import com.pojo.BooksSql;
import java.util.ArrayList;
public class Top_print {
public class TopPrint {
/**
......@@ -15,7 +15,7 @@ public class Top_print {
public static void search_top(ArrayList<Books> book_top){
ArrayList<Books> book_top_array = new ArrayList<>();
Books.book_top_array(book_top_array);
BooksSql.book_top_array(book_top_array);
int index = 0;
for (Books books_temp:book_top_array
......
package com.Service;
package com.Service.User.TimeOut;
import com.Dao.Books;
import com.Dao.Borrow;
import com.Dao.Return_before;
import com.pojo.BooksSql;
import com.pojo.BorrowSql;
import java.util.ArrayList;
public class Was_borrowed {
public class WasBorrowed {
/**
* 返回一个用户的借阅记录集合
......@@ -16,16 +18,13 @@ public class Was_borrowed {
*/
public static void was_borrowed(String user_id,ArrayList<Return_before> return_b ){
System.out.println();
return_b .clear();
ArrayList<Borrow> borrow_array = new ArrayList<>();
Borrow.borrow_to_array(borrow_array);
System.out.println("5555");
BorrowSql.borrow_to_array(borrow_array);
ArrayList<Books> book_array = new ArrayList<>();
Books.book_top_array(book_array);
BooksSql.book_top_array(book_array);
for (Borrow temp:borrow_array
......@@ -37,7 +36,6 @@ public class Was_borrowed {
Return_before a = new Return_before();
a.setUser_id(temp.getUser_id());
System.out.println(temp.getUser_id());
a.setBorrow_id(temp.getBorrow_id());
a.setManage_id(temp.getManage_id());
a.setBook_id(temp.getBook_id());
......@@ -45,8 +43,6 @@ public class Was_borrowed {
a.setBorrow_time(temp.getBorrow_time());
for (Books temp2:book_array
) {
System.out.println();
if (temp2.getId().equals(temp.getBook_id())){
a.setJdid(temp2.getJdid());
......
package com.Servlet.LoginServlet;
import com.Dao.Books;
import com.Service.User.TimeOut.TopPrint;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class LoginServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click_top_print = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click_top_print.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(click_top_print);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String b = a.getString("login_stnum");
String c = a.getString("login_input_password");
System.out.println(b+" "+c);
String json = null;
PrintWriter out = response.getWriter();
String d = "404";
if (b.equals("1") && c.equals("2")) {
ArrayList<Books> book_top = new ArrayList<>();
TopPrint.search_top(book_top);
JSONArray book_top_json = null;
json = JSON.toJSONString(book_top);
}
out.print(json);
}
}
package com.Servlet.ManageServlet;
import com.Dao.Return_before;
import com.Service.User.TimeOut.TimeOut;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class AllTimeOutServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder user_id = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
user_id.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(user_id);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String click = a.getString("click");
System.out.println(user_id);
System.out.println();
String json = null;
if(click.equals("1")){
ArrayList<Return_before> return_t = new ArrayList<>();
TimeOut.all_time_out(return_t);
json = JSON.toJSONString(return_t);
PrintWriter out = response.getWriter();
json = JSON.toJSONString(return_t);
out.print(json);
}
}
}
package com.Servlet.ManageServlet.Book;
import com.Dao.Books;
import com.Service.Manage.AddBook;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class AddBookServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(click);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String jdid = a.getString("jdid");
String bookshelf_id = a.getString("bookshelf_id");
String book_name = a.getString("book_name");
String category = a.getString("category");
String author = a.getString("author");
String publisher = a.getString("publisher");
String image = a.getString("image");
AddBook.add_book(jdid,bookshelf_id,book_name,category,author,publisher,image);
String json = null;
String d = "200";
PrintWriter out = response.getWriter();
out.print(d);
}
}
\ No newline at end of file
package com.Servlet.ManageServlet.Book;
import com.Dao.Books;
import com.Service.Manage.AddBook;
import com.Service.Manage.DeleteBook;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class DeleteBookServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(click);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String book_id = a.getString("book_id");
DeleteBook.delete_book(book_id);
String json = null;
String d = "200";
PrintWriter out = response.getWriter();
out.print(d);
}
}
\ No newline at end of file
package com.Servlet.ManageServlet.Book;
import com.Dao.Books;
import com.Service.Manage.AddBook;
import com.Service.Manage.FixBook;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class FixBookServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click.append((char) respInt);
respInt = inputStreamReader.read();
}
System.out.println("ssssssssss");
String jsonString = String.valueOf(click);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String book_id = a.getString("book_id");
String jdid = a.getString("jdid");
String bookshelf_id = a.getString("bookshelf_id");
String book_name = a.getString("book_name");
String category = a.getString("category");
String author = a.getString("author");
String publisher = a.getString("publisher");
String image = a.getString("image");
// System.out.println("ssssssssss2");
FixBook.fix_book(book_id,jdid,bookshelf_id,book_name,category,author,publisher,image);
// System.out.println("ssssssssss3");
String json = null;
String d = "200";
PrintWriter out = response.getWriter();
out.print(d);
}
}
\ No newline at end of file
package com.Servlet.ManageServlet.Choose;
import com.Service.Manage.IsReturn;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class AgreeBorrowServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("qqqqqqqq");
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click.append((char) respInt);
respInt = inputStreamReader.read();
}
System.out.println("555[[[");
String jsonString = String.valueOf(click);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String borrow_id = a.getString("borrow_id");
String json = null;
IsReturn.IsReturn(borrow_id,0);
String d = "200";
PrintWriter out = response.getWriter();
out.print(d);
}
}
\ No newline at end of file
package com.Servlet.ManageServlet.Choose;
import com.Service.Manage.IsReturn;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class AgreeReturnServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(click);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String borrow_id = a.getString("borrow_id");
String json = null;
IsReturn.IsReturn(borrow_id, 1);
String d = "200";
PrintWriter out = response.getWriter();
out.print(d);
}
}
\ No newline at end of file
package com.Servlet.ManageServlet.Choose;
import com.Service.Manage.IsReturn;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class RefuseBorrowServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(click);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String borrow_id = a.getString("borrow_id");
String json = null;
String d = "200";
IsReturn.IsReturn(borrow_id,4);
PrintWriter out = response.getWriter();
out.print(d);
}
}
\ No newline at end of file
package com.Servlet.ManageServlet.Choose;
import com.Service.Manage.IsReturn;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class RefuseReturnServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(click);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String borrow_id = a.getString("borrow_id");
String json = null;
IsReturn.IsReturn(borrow_id,0);
String d = "200";
PrintWriter out = response.getWriter();
out.print(d);
}
}
\ No newline at end of file
package com.Servlet.ManageServlet;
import com.Dao.Return_before;
import com.Service.Manage.PrintBorrowed;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class PrintApplyServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder user_id = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
user_id.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(user_id);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String click = a.getString("click");
String json = null;
ArrayList<Return_before> return_t = new ArrayList<>();
if(click.equals("1")) {
PrintBorrowed.print_require(return_t,3);
json = JSON.toJSONString(return_t);
}
PrintWriter out = response.getWriter();
json = JSON.toJSONString(return_t);
out.print(json);
}
}
package com.Servlet.ManageServlet;
import com.Dao.Books;
import com.Service.Timing;
import com.Service.User.TimeOut.TopPrint;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pojo.BooksSql;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class PrintBookServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Timing c = new Timing();
c.start();
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder click_top_print = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
click_top_print.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(click_top_print);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String b = a.getString("click");
String json = null;
if (b.equals("1")) {
ArrayList<Books> book_array = new ArrayList<>();
BooksSql.books_to_array(book_array);
JSONArray book_top_json = null;
json = JSON.toJSONString(book_array);
}
PrintWriter out = response.getWriter();
out.print(json);
}
}
package com.Servlet.ManageServlet;
import com.Dao.Return_before;
import com.Service.Manage.PrintBorrowed;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class PrintBorrowedServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder user_id = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
user_id.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(user_id);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String click = a.getString("click");
String json = null;
ArrayList<Return_before> return_t = new ArrayList<>();
if(click.equals("1")) {
PrintBorrowed.print_borrowed(return_t);
json = JSON.toJSONString(return_t);
}
PrintWriter out = response.getWriter();
json = JSON.toJSONString(return_t);
out.print(json);
}
}
package com.Servlet.ManageServlet;
import com.Dao.Return_before;
import com.Service.Manage.PrintBorrowed;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class PrintReturnServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder user_id = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
user_id.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(user_id);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String click = a.getString("click");
String json = null;
ArrayList<Return_before> return_t = new ArrayList<>();
if(click.equals("1")) {
PrintBorrowed.print_require(return_t,2);
json = JSON.toJSONString(return_t);
}
PrintWriter out = response.getWriter();
json = JSON.toJSONString(return_t);
out.print(json);
}
}
package com.Servlet.UserServlet;
import com.Service.Manage.IsReturn;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class BorrowServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder inf = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
inf.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(inf);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String book_id = a.getString("book_id");
String user_id = a.getString("user_id");
String json = null;
IsReturn.IsReturn(book_id,user_id,3);
PrintWriter out = response.getWriter();
String d = "200";
json = JSON.toJSONString(d);
out.print(json);
}
}
\ No newline at end of file
package com.Servlet;
package com.Servlet.UserServlet;
import com.Dao.Books;
import com.Dao.Borrow;
import com.Service.Time_out;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pojo.BooksSql;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
......@@ -19,11 +18,12 @@ import java.util.ArrayList;
@Configuration
public class Time_outServlet extends HttpServlet {
public class GuideSearchServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
......@@ -33,27 +33,29 @@ public class Time_outServlet extends HttpServlet {
int respInt = inputStreamReader.read();
while (respInt != -1) {
user_id.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(user_id);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String userid = a.getString("user_id");
String choose = a.getString("choose");
System.out.println(user_id);
System.out.println();
String json = null;
ArrayList<Borrow> time_out = new ArrayList<>();
Time_out.time_out(userid,time_out);
json = JSON.toJSONString(time_out);
ArrayList<Books> require = new ArrayList<>();
BooksSql.guide(choose,require);
json = JSON.toJSONString(require);
PrintWriter out = response.getWriter();
json = JSON.toJSONString(time_out);
json = JSON.toJSONString(require);
out.print(json);
}
......
package com.Servlet.UserServlet;
import com.Dao.Books;
import com.Dao.Return_before;
import com.Service.User.TimeOut.PrintBook;
import com.Service.User.TimeOut.TimeOut;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class PrintBookServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder user_id = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
user_id.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(user_id);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String click = a.getString("click");
System.out.println(user_id);
System.out.println();
String json = null;
ArrayList<Books> book_array = new ArrayList<>();
if (click.equals("1")) {
PrintBook.search_all(book_array);
json = JSON.toJSONString(book_array);
}
PrintWriter out = response.getWriter();
json = JSON.toJSONString(book_array);
out.print(json);
}
}
package com.Servlet.UserServlet;
import com.Service.Manage.IsReturn;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
@Configuration
public class ReturnServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder inf = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
inf.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(inf);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String borrow_id = a.getString("borrow_id");
String json = null;
IsReturn.IsReturn(borrow_id,2);
PrintWriter out = response.getWriter();
String d = "200";
json = JSON.toJSONString(d);
out.print(json);
}
}
\ No newline at end of file
package com.Servlet.UserServlet;
import com.Dao.Books;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pojo.BooksSql;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class SearchNameServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder user_id = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
user_id.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(user_id);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String book_name = a.getString("book_name");
String json = null;
ArrayList<Books> require = new ArrayList<>();
BooksSql.search_name(book_name,require);
PrintWriter out = response.getWriter();
json = JSON.toJSONString(require);
out.print(json);
}
}
package com.Servlet.UserServlet;
import com.Dao.Return_before;
import com.Service.User.TimeOut.TimeOut;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.context.annotation.Configuration;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@Configuration
public class TimeOutServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
response.setCharacterEncoding("utf-8");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder user_id = new StringBuilder();
int respInt = inputStreamReader.read();
while (respInt != -1) {
user_id.append((char) respInt);
respInt = inputStreamReader.read();
}
String jsonString = String.valueOf(user_id);// 将 char 数组 data 转换成字符串
JSONObject a = JSON.parseObject(jsonString);
String userid = a.getString("user_id");
System.out.println(user_id);
// System.out.println();
String json = null;
ArrayList<Return_before> return_t = new ArrayList<>();
TimeOut.time_out(userid,return_t);
json = JSON.toJSONString(return_t);
PrintWriter out = response.getWriter();
json = JSON.toJSONString(return_t);
out.print(json);
}
}
package com.Servlet;
package com.Servlet.UserServlet;
import com.Dao.Books;
import com.Service.Timing;
import com.Service.Top_print;
import com.Service.User.TimeOut.TopPrint;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
......@@ -20,11 +20,12 @@ import java.util.ArrayList;
@Configuration
public class Top_printServlet extends HttpServlet {
public class TopPrintServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("777qqqq");
Timing c = new Timing();
c.start();
......@@ -51,7 +52,7 @@ public class Top_printServlet extends HttpServlet {
if (b.equals("1")) {
ArrayList<Books> book_top = new ArrayList<>();
Top_print.search_top(book_top);
TopPrint.search_top(book_top);
JSONArray book_top_json = null;
json = JSON.toJSONString(book_top);
......
package com.Servlet;
package com.Servlet.UserServlet;
import com.Dao.Return_before;
import com.Service.Top_print;
import com.Service.Was_borrowed;
import com.Service.User.TimeOut.WasBorrowed;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
......@@ -17,7 +15,7 @@ import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
public class Was_borrowedServlet extends HttpServlet {
public class WasBorrowedServlet extends HttpServlet {
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
......@@ -25,6 +23,7 @@ public class Was_borrowedServlet extends HttpServlet {
response.setCharacterEncoding("utf-8");
System.out.println("77777777");
//fastjson
InputStreamReader inputStreamReader = new InputStreamReader(request.getInputStream(), StandardCharsets.UTF_8);
StringBuilder user_id = new StringBuilder();
......@@ -42,7 +41,7 @@ public class Was_borrowedServlet extends HttpServlet {
String json = null;
ArrayList<Return_before> return_b = new ArrayList<>();
Was_borrowed.was_borrowed(b,return_b);
WasBorrowed.was_borrowed(b,return_b);
json = JSON.toJSONString(return_b);
......
package com.example.javaproject2;
import java.sql.*;
import java.util.ArrayList;
import java.sql.*;
public class Data {
private String id;
private String food_name;
private int price;
private String jpg_adr;
private int value;
// public static void add_array(String id, String food_name, int price, String jpg_adr,int value, ArrayList<Data> array){
// Data a = new Data();
// a.setId(id);
// a.setFood_name(food_name);
// a.setPrice(price);
// a.setJpg_adr(jpg_adr);
// a.setValue(value);
// array.add(a);
// }
//
// public static void database(ArrayList<Data> array){
// add_array("001","寿司",13,"images/寿司.jpg",0,array);
// add_array("002","麻辣鱼",13,"images/麻辣鱼.jpg",1,array);
// add_array("003","重庆串串加面",18,"images/重庆串串加面.jpg",2,array);
// add_array("004","大闸蟹",27,"images/大闸蟹.gif",3,array);
// add_array("005","披萨",25,"images/ps2.jpg",4,array);
//
//
// }
public Data(String id, String food_name, int price, String jpg_adr,int value) {
this.id = id;
this.value = value;
this.food_name = food_name;
this.price = price;
this.jpg_adr = jpg_adr;
}
public Data() {
}
public int getValue() {
return value;
}
public void setValue(int value) {
this.value = value;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getFood_name() {
return food_name;
}
public void setFood_name(String food_name) {
this.food_name = food_name;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public String getJpg_adr() {
return jpg_adr;
}
public void setJpg_adr(String jpg_adr) {
this.jpg_adr = jpg_adr;
}
}
package com.example.javaproject2;
import java.io.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
private String message;
public void init() {
message = "Hello World!";
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
response.setContentType("text/html");
// Hello
PrintWriter out = response.getWriter();
out.println("<html><body>");
out.println("<h1>" + message + "</h1>");
out.println("</body></html>");
}
public void destroy() {
}
}
\ No newline at end of file
package com.example.javaproject2;
import java.sql.*;
public class Login_compare {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
// static final String DB_URL = "jdbc:mysql://localhost:3306/school";
public static int compare(String username1, String password1) {
Connection conn = null;
Statement stmt = null;
try {
//STEP 2: Register JDBC driver
Class.forName("com.mysql.cj.jdbc.Driver");
//
// //STEP 3: Open a connection
System.out.println("Connecting to database...");
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/restaurant?characterEncoding=utf8&useSSL=false&serverTimezone=GMT%2B8","root","sunwutong9");
// //STEP 4: Execute a query
System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql;
sql = "SELECT * FROM user where username = '"+username1+"'and password = '"+password1+"'";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
while (rs.next()) {
return 2;
}
//STEP 6: Clean-up environment
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try
return 1;
}//end main
}//end FirstExample - by www.yiibai.com//原文出自【易百教程】,商业转载请联系作者获得授权,非商业请保留原文链接:https://www.yiibai.com/jdbc/jdbc_quick_guide.html
package com.example.javaproject2;
public class User {
}
package com.pojo;
import com.Dao.Books;
import com.Dao.Borrow;
import com.Dao.User;
import com.Service.Tool.GenerateUuid;
import java.sql.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
public class BorrowSql {
/**
* 增加借书记录
* @param book
* @param user
* @param is_return
*/
public static void add_borrow(Books book, User user, int is_return){
Connection conn = null;
// System.out.println("44444");
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
// System.out.println("Connecting to database...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
String date = simpleDateFormat.format(new java.util.Date());
String manage_id = "5555";
// System.out.println("Creating statement ...");
stmt = conn.createStatement();
String sql = "INSERT INTO borrow (user_id,borrow_id,manage_id,book_id," +
"username,book_name,borrow_time,is_return,already_remind) VALUES ('"+user.getUser_id()+"','"+
GenerateUuid.create_uuid() +"','"+manage_id+"','"+book.getId()+"','"+
user.getUsername()+"','"+book.getBook_name()+"','"+ "null"+"',"+3+","
+0+" )";
stmt.executeUpdate(sql);
conn.setAutoCommit(false);
conn.commit();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try
}
/**
* 改变状态
* @param borrow_id
*/
public static void change_is_return(String borrow_id,int is_return){
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
// System.out.println("Connecting to database...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
// System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "UPDATE borrow " +
" set is_return = "+is_return
+" where borrow_id = '"+borrow_id+"'";
// System.out.println(sql);
stmt.executeUpdate(sql);
conn.setAutoCommit(false);
conn.commit();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try id,user_uuid,borrow_uuid,manage_uuid,book_uuid,username,book_name,borrow_time,is_return
}
/**
* 同意借书
* @param borrow_id
*/
public static void agree_borrow(String borrow_id){
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
// System.out.println("Connecting to database...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
// System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "UPDATE borrow " +
" set is_return = "+0
+" where borrow_id = '"+borrow_id+"'";
System.out.println(sql);
stmt.executeUpdate(sql);
conn.setAutoCommit(false);
conn.commit();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try id,user_uuid,borrow_uuid,manage_uuid,book_uuid,username,book_name,borrow_time,is_return
}
/**
* 将所有历史借书记录转为集合
* @param borrow_array
*/
public static void borrow_to_array(ArrayList<Borrow> borrow_array){
borrow_array.clear();
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
// System.out.println("Connecting to database...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
// System.out.println("Creating statement...");
stmt = conn.createStatement();
String sql = "SELECT * FROM borrow";
ResultSet rs = stmt.executeQuery(sql);
conn.setAutoCommit(false);
while (rs.next()) {
String user_id = rs.getString("user_id");
String borrow_id = rs.getString("borrow_id");
String manage_id = rs.getString("manage_id");
String book_id = rs.getString("book_id");
String username = rs.getString("username");
String book_name = rs.getString("book_name");
String borrow_time = rs.getString("borrow_time");
int is_return = rs.getInt("is_return");
int already_remind = rs.getInt("already_remind");
BorrowSql.borrow_to_arr(user_id,borrow_id,manage_id,book_id,username,book_name,borrow_time,is_return,already_remind,borrow_array);
}
conn.commit();
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try id,user_uuid,borrow_uuid,manage_uuid,book_uuid,username,book_name,borrow_time,is_return
}
/**
* 将东西放到对象里
* @param user_id
* @param borrow_id
* @param manage_id
* @param book_id
* @param username
* @param book_name
* @param borrow_time
* @param is_return
* @param already_remind
* @param borrow_array
*/
public static void borrow_to_arr(String user_id, String borrow_id,
String manage_id, String book_id,
String username,String book_name,String borrow_time,
int is_return,int already_remind,ArrayList<Borrow> borrow_array){
Borrow borrow = new Borrow();
borrow.setBorrow_id(borrow_id);
borrow.setUsername(username);
borrow.setUser_id(user_id);
borrow.setBook_name(book_name);
borrow.setBook_id(book_id);
borrow.setManage_id(manage_id);
borrow.setBorrow_time(borrow_time);
borrow.setIs_return(is_return);
borrow.setAlready_remind(already_remind);
borrow_array.add(borrow);
}
}
package com.pojo;
import com.Dao.User;
import java.sql.*;
import java.util.ArrayList;
public class UserSql {
public static void user_to_array(ArrayList<User> user_array){
user_array.clear();
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
// System.out.println("Connecting to database...");
String url = "jdbc:mysql://localhost:3306/book_system?characterEncoding=UTF-8&useSSL=false&serverTimezone=GMT%2B8";
String root = "root";
String password = "sunwutong9";
conn = DriverManager.getConnection(url,root,password);
// System.out.println("Creating statement user...");
stmt = conn.createStatement();
String sql = "SELECT * FROM user ";
ResultSet rs = stmt.executeQuery(sql);
conn.setAutoCommit(false);
while (rs.next()) {
// int id, int borrowing_books, String user_uuid,String student_id,String user_password, String phone_number,String qq_mail
int borrowing_books = rs.getInt("borrowing_books");
String user_id = rs.getString("user_id");
String student_id = rs.getString("student_id");
String user_password = rs.getString("user_password");
String phone_number = rs.getString("phone_number");
String username = rs.getString("username");
String qq_mail = rs.getString("qq_mail");
UserSql.user_to_arr(borrowing_books,user_id,username,student_id,user_password,phone_number,qq_mail,user_array);
}
conn.commit();
rs.close();
stmt.close();
conn.close();
} catch (SQLException se) {
//Handle errors for JDBC
se.printStackTrace();
} catch (Exception e) {
//Handle errors for Class.forName
e.printStackTrace();
} finally {
//finally block used to close resources
try {
if (stmt != null)
stmt.close();
} catch (SQLException se2) {
}// nothing we can do
try {
if (conn != null)
conn.close();
} catch (SQLException se) {
se.printStackTrace();
}//end finally try
}//end try
}
public static void user_to_arr(int borrowing_books, String user_id,String username,
String student_id,String user_password,
String phone_number,String qq_mail,ArrayList<User> user_array){
User user = new User();
user.setBorrowing_books(borrowing_books);
user.setUser_id(user_id);
user.setUsername(username);
user.setStudent_id(student_id);
user.setUser_password(user_password);
user.setPhone_number(phone_number);
user.setQq_mail(qq_mail);
user_array.add(user);
}
}
......@@ -5,46 +5,198 @@
version="4.0">
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>LoginServlet</servlet-class>
<servlet-name>RefuseBorrowServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.Choose.RefuseBorrowServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
<servlet-name>RefuseBorrowServlet</servlet-name>
<url-pattern>/RefuseBorrowServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Top_printServlet</servlet-name>
<servlet-class>com.Servlet.Top_printServlet</servlet-class>
<servlet-name>AgreeBorrowServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.Choose.AgreeBorrowServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Top_printServlet</servlet-name>
<url-pattern>/Top_printServlet</url-pattern>
<servlet-name>AgreeBorrowServlet</servlet-name>
<url-pattern>/AgreeBorrowServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Was_borrowedServlet</servlet-name>
<servlet-class>com.Servlet.Was_borrowedServlet</servlet-class>
<servlet-name>RefuseReturnServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.Choose.RefuseReturnServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Was_borrowedServlet</servlet-name>
<url-pattern>/Was_borrowedServlet</url-pattern>
<servlet-name>RefuseReturnServlet</servlet-name>
<url-pattern>/RefuseReturnServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AgreeReturnServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.Choose.AgreeReturnServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AgreeReturnServlet</servlet-name>
<url-pattern>/AgreeReturnServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>TopPrintServlet</servlet-name>
<servlet-class>com.Servlet.UserServlet.TopPrintServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TopPrintServlet</servlet-name>
<url-pattern>/TopPrintServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>WasBorrowedServlet</servlet-name>
<servlet-class>com.Servlet.UserServlet.WasBorrowedServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>WasBorrowedServlet</servlet-name>
<url-pattern>/WasBorrowedServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>TimeOutServlet</servlet-name>
<servlet-class>com.Servlet.UserServlet.TimeOutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TimeOutServlet</servlet-name>
<url-pattern>/TimeOutServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>PrintBorrowedServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.PrintBorrowedServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PrintBorrowedServlet</servlet-name>
<url-pattern>/PrintBorrowedServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AddBookServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.Book.AddBookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AddBookServlet</servlet-name>
<url-pattern>/AddBookServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>DeleteBookServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.Book.DeleteBookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DeleteBookServlet</servlet-name>
<url-pattern>/DeleteBookServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>FixBookServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.Book.FixBookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FixBookServlet</servlet-name>
<url-pattern>/FixBookServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>GuideSearchServlet</servlet-name>
<servlet-class>com.Servlet.UserServlet.GuideSearchServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>GuideSearchServlet</servlet-name>
<url-pattern>/GuideSearchServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>PrintBookServlet</servlet-name>
<servlet-class>com.Servlet.UserServlet.PrintBookServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PrintBookServlet</servlet-name>
<url-pattern>/PrintBookServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>SearchNameServlet</servlet-name>
<servlet-class>com.Servlet.UserServlet.SearchNameServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SearchNameServlet</servlet-name>
<url-pattern>/SearchNameServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>BorrowServlet</servlet-name>
<servlet-class>com.Servlet.UserServlet.BorrowServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>BorrowServlet</servlet-name>
<url-pattern>/BorrowServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>ReturnServlet</servlet-name>
<servlet-class>com.Servlet.UserServlet.ReturnServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ReturnServlet</servlet-name>
<url-pattern>/ReturnServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Time_outServlet</servlet-name>
<servlet-class>com.Servlet.Time_outServlet</servlet-class>
<servlet-name>PrintApplyServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.PrintApplyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Time_outServlet</servlet-name>
<url-pattern>/Time_outServlet</url-pattern>
<servlet-name>PrintApplyServlet</servlet-name>
<url-pattern>/PrintApplyServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>PrintReturnServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.PrintReturnServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PrintReturnServlet</servlet-name>
<url-pattern>/PrintReturnServlet</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>AllTimeOutServlet</servlet-name>
<servlet-class>com.Servlet.ManageServlet.AllTimeOutServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AllTimeOutServlet</servlet-name>
<url-pattern>/AllTimeOutServlet</url-pattern>
</servlet-mapping>
<filter>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment