-
-
Save turbotree/6991753 to your computer and use it in GitHub Desktop.
图书管理系统1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc.librarysystem.entity; | |
public class Admin { | |
private int id; | |
private String username; | |
private String password; | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getUsername() { | |
return username; | |
} | |
public void setUsername(String username) { | |
this.username = username; | |
} | |
public String getPassword() { | |
return password; | |
} | |
public void setPassword(String password) { | |
this.password = password; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc.librarysystem.dao; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.util.List; | |
import com.jdbc.librarysystem.entity.Admin; | |
import com.jdbc.librarysystem.util.DBHelp; | |
import com.jdbc.librarysystem.util.RowMapper; | |
public class AdminDao<T> { | |
private DBHelp<Admin> db = new DBHelp<Admin>(); | |
/** | |
* 查询管理员信息 | |
* @param name | |
* @return | |
*/ | |
public Admin findByName(String name){ | |
String sql = "select id,username,`password` from t_admin where username = ?"; | |
return db.executeQureyToObject(sql, new AdminRowMapper(), name); | |
} | |
public Admin findByNameAndPassword(String name, String password) { | |
String sql = "select id,username,`password` from t_admin where username = ? and `password` = ?"; | |
return db.executeQureyToObject(sql, new AdminRowMapper(), name,password); | |
} | |
/** | |
* 保存管理员信息 | |
* @param admin | |
* @return | |
*/ | |
public int save(Admin admin) { | |
String sql = "insert into t_account(username,`password`) values (?,?)"; | |
return db.executeSQL(sql, admin.getUsername(),admin.getPassword()); | |
} | |
/** | |
* 删除管理员信息 | |
* @param id | |
* @return | |
*/ | |
public int delete(int id){ | |
String sql = "delete from t_admin where id = ?"; | |
return db.executeSQL(sql, id); | |
} | |
/** | |
* 修改管理员信息 | |
* @param user | |
* @return | |
*/ | |
public int update(Admin user) { | |
String sql = "update t_admin set username = ?,password = ? where id = ?"; | |
return db.executeSQL(sql, user.getUsername(),user.getPassword(),user.getId()); | |
} | |
/** | |
* 显示所有管理员信息 | |
* @return | |
*/ | |
public List<Admin> showAll() { | |
String sql = "select id,username,password from t_admin"; | |
return db.executeQueryToList(sql, new AdminRowMapper(){ | |
//匿名局部内部类 | |
@Override | |
public Admin mapRow(ResultSet rs) throws SQLException { | |
Admin admin = new Admin(); | |
admin.setId(rs.getInt("id")); | |
admin.setUsername(rs.getString("username")); | |
return admin; | |
} | |
}); | |
} | |
/** | |
* 创建的一个AccountRowMapper实现类实现RowMapper接口 | |
* @author 抽烟别碰电脑 | |
* | |
*/ | |
private class AdminRowMapper implements RowMapper<Admin> { | |
@Override | |
public Admin mapRow(ResultSet rs) throws SQLException { | |
Admin admin = new Admin(); | |
admin.setId(rs.getInt("id")); | |
admin.setUsername(rs.getString("username")); | |
admin.setPassword(rs.getString("password")); | |
return admin; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc.librarysystem.entity; | |
public class Book { | |
private int id; | |
private String bookId; | |
private String bookName; | |
private String author; | |
private String pubName; | |
private int maxNum; | |
private int nowNum; | |
public Book(){}; | |
public Book(String bookId, String bookName, String author, String pubName, | |
int maxNum, int nowNum) { | |
super(); | |
this.bookId = bookId; | |
this.bookName = bookName; | |
this.author = author; | |
this.pubName = pubName; | |
this.maxNum = maxNum; | |
this.nowNum = nowNum; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getBookName() { | |
return bookName; | |
} | |
public void setBookName(String bookName) { | |
this.bookName = bookName; | |
} | |
public String getAuthor() { | |
return author; | |
} | |
public void setAuthor(String author) { | |
this.author = author; | |
} | |
public String getPubName() { | |
return pubName; | |
} | |
public void setPubName(String publishName) { | |
this.pubName = publishName; | |
} | |
public int getMaxNum() { | |
return maxNum; | |
} | |
public void setMaxNum(int maxNum) { | |
this.maxNum = maxNum; | |
} | |
public int getNowNum() { | |
return nowNum; | |
} | |
public void setNowNum(int nowNum) { | |
this.nowNum = nowNum; | |
} | |
public String getBookId() { | |
return bookId; | |
} | |
public void setBookId(String bookId) { | |
this.bookId = bookId; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc.librarysystem.dao; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.util.List; | |
import com.jdbc.librarysystem.entity.Book; | |
import com.jdbc.librarysystem.util.DBHelp; | |
import com.jdbc.librarysystem.util.RowMapper; | |
public class BookDao<T> { | |
private DBHelp<Book> db = new DBHelp<Book>(); | |
/** | |
* 根据不同条件查找书籍 | |
* @param 条件 | |
* @return | |
*/ | |
public Book findByBookId(String index){ | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book where bookId = ?"; | |
return db.executeQureyToObject(sql, new BookRowMapper(),index); | |
} | |
public Book findById(int Id){ | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book where id = ?"; | |
return db.executeQureyToObject(sql, new BookRowMapper(),Id); | |
} | |
/** | |
* 保存书籍信息 | |
* @param book | |
* @return | |
*/ | |
public int save(Book book) { | |
String sql = "insert into t_book(bookId,bookName,author,pubName,maxNum,nowNum) values (?,?,?,?,?,?)"; | |
return db.executeSQL(sql, book.getBookId(),book.getBookName(),book.getAuthor(),book.getPubName(),book.getMaxNum(),book.getNowNum()); | |
} | |
/** | |
* 根据书籍编号删除书籍 | |
* @param 书籍编号 | |
* @return | |
*/ | |
public int delete(String bookId){ | |
String sql = "delete from t_book where bookId = ?"; | |
return db.executeSQL(sql, bookId); | |
} | |
/** | |
* 修改书籍信息 | |
* @param book | |
* @return | |
*/ | |
public int update(Book book) { | |
String sql = "update t_book set bookId = ?,bookName = ?,author = ?,pubName = ?,maxNum = ?,nowNum = ? where id = ?"; | |
return db.executeSQL(sql, book.getBookId(),book.getBookName(),book.getAuthor(),book.getPubName(),book.getMaxNum(),book.getNowNum(), book.getId()); | |
} | |
/** | |
* 查询所有书籍 | |
* @return | |
*/ | |
public List<Book> showAll() { | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book"; | |
return db.executeQueryToList(sql, new BookRowMapper()); | |
} | |
/** | |
* 利用迷糊查询查找所有符合条件的书籍信息 | |
* @param 查询条件 | |
* @return | |
*/ | |
public List<Book> showAllByBookName(String index) { | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book where bookName like ?"; | |
return db.executeQueryToList(sql, new BookRowMapper(),"%"+index+"%"); | |
} | |
public List<Book> showAllByBookId(String index) { | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book where bookId like ?"; | |
return db.executeQueryToList(sql, new BookRowMapper(),"%"+index+"%"); | |
} | |
public List<Book> showAllByAuthor(String index) { | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book where author like ?"; | |
return db.executeQueryToList(sql, new BookRowMapper(),"%"+index+"%"); | |
} | |
public List<Book> showAllByPubName(String index) { | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book where pubName like ?"; | |
return db.executeQueryToList(sql, new BookRowMapper(),"%"+index+"%"); | |
} | |
public List<Book> showAllByMaxNum(String index) { | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book where maxNum like ?"; | |
return db.executeQueryToList(sql, new BookRowMapper(),"%"+index+"%"); | |
} | |
public List<Book> showAllByNowNum(String index) { | |
String sql = "select id,bookId,bookName,author,pubName,maxNum,nowNum from t_book where nowNum like ?"; | |
return db.executeQueryToList(sql, new BookRowMapper(),"%"+index+"%"); | |
} | |
/** | |
* 创建的一个AccountRowMapper实现类实现RowMapper接口 | |
* @author 抽烟别碰电脑 | |
* | |
*/ | |
private class BookRowMapper implements RowMapper<Book> { | |
@Override | |
public Book mapRow(ResultSet rs) throws SQLException { | |
Book book = new Book(); | |
book.setId(rs.getInt("id")); | |
book.setBookId(rs.getString("bookId")); | |
book.setBookName(rs.getString("bookName")); | |
book.setAuthor(rs.getString("author")); | |
book.setPubName(rs.getString("pubName")); | |
book.setMaxNum(rs.getInt("maxNum")); | |
book.setNowNum(rs.getInt("nowNum")); | |
return book; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc.librarysystem.entity; | |
public class Card { | |
private int id; | |
private String number; | |
private String name; | |
private String sex; | |
private String address; | |
private String tel; | |
public Card(){}; | |
public Card(String number, String name, String sex, String address, | |
String tel) { | |
this.number = number; | |
this.name = name; | |
this.sex = sex; | |
this.address = address; | |
this.tel = tel; | |
} | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public String getSex() { | |
return sex; | |
} | |
public void setSex(String sex) { | |
this.sex = sex; | |
} | |
public String getAddress() { | |
return address; | |
} | |
public void setAddress(String address) { | |
this.address = address; | |
} | |
public String getTel() { | |
return tel; | |
} | |
public void setTel(String tel) { | |
this.tel = tel; | |
} | |
public String getNumber() { | |
return number; | |
} | |
public void setNumber(String number) { | |
this.number = number; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc.librarysystem.dao; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.util.List; | |
import com.jdbc.librarysystem.entity.Card; | |
import com.jdbc.librarysystem.util.DBHelp; | |
import com.jdbc.librarysystem.util.RowMapper; | |
public class CardDao<T> { | |
private DBHelp<Card> db = new DBHelp<Card>(); | |
/** | |
* 根据条件查询图书证信息 | |
* @param 查询条件 | |
* @return | |
*/ | |
public Card findByNum(String number){ | |
String sql = "select id,number,name,sex,address,tel from t_card where number = ?"; | |
return db.executeQureyToObject(sql, new CardRowMapper(), number); | |
} | |
public Card findById(int id){ | |
String sql = "select id,number,name,sex,address,tel from t_card where id = ?"; | |
return db.executeQureyToObject(sql, new CardRowMapper(), id); | |
} | |
/** | |
* 保存图书证信息 | |
* @param card | |
* @return | |
*/ | |
public int save(Card card) { | |
String sql = "insert into t_card(number,name,sex,address,tel) values (?,?,?,?,?)"; | |
return db.executeSQL(sql, card.getNumber(),card.getName(),card.getSex(),card.getAddress(),card.getTel()); | |
} | |
/** | |
* 删除图书证信息 | |
* @param 根据图书证编号 | |
* @return | |
*/ | |
public int delete(int number){ | |
String sql = "delete from t_card where number = ?"; | |
return db.executeSQL(sql, number); | |
} | |
/** | |
* 修改图书证信息 | |
* @param user | |
* @return | |
*/ | |
public int update(Card user) { | |
String sql = "update t_card set number = ?,name = ?,sex = ?,address = ?,tel = ? where id = ?"; | |
return db.executeSQL(sql, user.getNumber(),user.getName(),user.getSex(),user.getAddress(),user.getTel(),user.getId()); | |
} | |
/** | |
* 显示所有图书证信息 | |
* @return | |
*/ | |
public List<Card> showAll() { | |
String sql = "select id,number,name,sex,address,tel from t_card"; | |
return db.executeQueryToList(sql, new CardRowMapper(){ | |
//匿名局部内部类(备用) | |
@Override | |
public Card mapRow(ResultSet rs) throws SQLException { | |
Card card = new Card(); | |
card.setId(rs.getInt("id")); | |
card.setNumber(rs.getString("number")); | |
card.setName(rs.getString("name")); | |
card.setSex(rs.getString("sex")); | |
card.setAddress(rs.getString("address")); | |
card.setTel(rs.getString("tel")); | |
return card; | |
} | |
}); | |
} | |
/** | |
* 创建的一个AccountRowMapper实现类实现RowMapper接口 | |
* @author 抽烟别碰电脑 | |
* | |
*/ | |
private class CardRowMapper implements RowMapper<Card> { | |
@Override | |
public Card mapRow(ResultSet rs) throws SQLException { | |
Card card = new Card(); | |
card.setId(rs.getInt("id")); | |
card.setNumber(rs.getString("number")); | |
card.setName(rs.getString("name")); | |
card.setSex(rs.getString("sex")); | |
card.setAddress(rs.getString("address")); | |
card.setTel(rs.getString("tel")); | |
return card; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc.librarysystem.entity; | |
public class Record { | |
private int id; | |
private int bid; | |
private int cid; | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public int getBid() { | |
return bid; | |
} | |
public void setBid(int bid) { | |
this.bid = bid; | |
} | |
public int getCid() { | |
return cid; | |
} | |
public void setCid(int cid) { | |
this.cid = cid; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.jdbc.librarysystem.dao; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.util.List; | |
import com.jdbc.librarysystem.entity.Record; | |
import com.jdbc.librarysystem.util.DBHelp; | |
import com.jdbc.librarysystem.util.RowMapper; | |
public class RecordDao<T> { | |
private DBHelp<Record> db = new DBHelp<Record>(); | |
/** | |
* 根据不同条件查看借书记录 | |
* @param 查询条件 | |
* @return | |
*/ | |
public Record findById(int id){ | |
String sql = "select id,bid,cid from t_record where id = ?"; | |
return db.executeQureyToObject(sql, new RecordRowMapper(), id); | |
} | |
public Record findByBid(int bid){ | |
String sql = "select id,bid,cid from t_record where bid = ?"; | |
return db.executeQureyToObject(sql, new RecordRowMapper(), bid); | |
} | |
public Record findByCid(int cid){ | |
String sql = "select id,bid,cid from t_record where cid = ?"; | |
return db.executeQureyToObject(sql, new RecordRowMapper(), cid); | |
} | |
/** | |
* 保存借书记录 | |
* @param record | |
* @return | |
*/ | |
public int save(Record record) { | |
String sql = "insert into t_record(bid,cid) values (?,?)"; | |
return db.executeSQL(sql, record.getBid(),record.getCid()); | |
} | |
/** | |
* 根据id删除借书记录 | |
* @param id | |
* @return | |
*/ | |
public int delete(int id){ | |
String sql = "delete from t_record where id = ?"; | |
return db.executeSQL(sql, id); | |
} | |
/** | |
* 修改借书记录 | |
* @param record | |
* @return | |
*/ | |
public int update(Record record) { | |
String sql = "update t_record set bid = ?,cid = ? where id = ?"; | |
return db.executeSQL(sql, record.getBid(),record.getCid(),record.getId()); | |
} | |
/** | |
* 查看所有借书记录 | |
* @return | |
*/ | |
public List<Record> showAll() { | |
String sql = "select id,bid,cid from t_record"; | |
return db.executeQueryToList(sql, new RecordRowMapper(){ | |
//匿名局部内部类 | |
@Override | |
public Record mapRow(ResultSet rs) throws SQLException { | |
Record record = new Record(); | |
record.setId(rs.getInt("id")); | |
record.setBid(rs.getInt("bid")); | |
record.setCid(rs.getInt("cid")); | |
return record; | |
} | |
}); | |
} | |
/** | |
* 创建的一个AccountRowMapper实现类实现RowMapper接口 | |
* @author 抽烟别碰电脑 | |
* | |
*/ | |
private class RecordRowMapper implements RowMapper<Record> { | |
@Override | |
public Record mapRow(ResultSet rs) throws SQLException { | |
Record record = new Record(); | |
record.setId(rs.getInt("id")); | |
record.setBid(rs.getInt("bid")); | |
record.setCid(rs.getInt("cid")); | |
return record; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment