该项目是图书管理系统,共有八个基础类
Admin.java
public class Admin {
private Integer id;
private String password;
private String username;
public Admin(String username,String password) {
super();
this.username = username;
this.password = password;
}
public Admin() {
super();
// TODO Auto-generated constructor stub
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
@Override
public String toString() {
return "Admin [id=" + id + ", username=" + username + ", password=" + password + "]";
}
}
Back.java
public class Back {
private Integer id;
private String bar;
private String stuname;
private String stuid;
private String isbn;
private String book;
private String date;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
public String getStuname() {
return stuname;
}
public void setStuname(String stuname) {
this.stuname = stuname;
}
public String getStuid() {
return stuid;
}
public void setStuid(String stuid) {
this.stuid = stuid;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getBook() {
return book;
}
public void setBook(String book) {
this.book = book;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
Black.java
public class Black {
private Integer id;
private String stu_id;
private String stu_name;
public Black() {
super();
// TODO Auto-generated constructor stub
}
public Black(String stu_id, String stu_name) {
super();
this.stu_id = stu_id;
this.stu_name = stu_name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getStu_id() {
return stu_id;
}
public void setStu_id(String stu_id) {
this.stu_id = stu_id;
}
public String getStu_name() {
return stu_name;
}
public void setStu_name(String stu_name) {
this.stu_name = stu_name;
}
}
Book.java
public class Book {
private Integer id;
private String isbn;
private String bookname;
private Integer count;
private String publish;
private String booktype;
private String author;
public Book() {
super();
// TODO Auto-generated constructor stub
}
public Book(String isbn, String bookname, Integer count, String publish, String booktype, String author) {
super();
this.isbn = isbn;
this.bookname = bookname;
this.count = count;
this.publish = publish;
this.booktype = booktype;
this.author = author;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public String getPublish() {
return publish;
}
public void setPublish(String publish) {
this.publish = publish;
}
public String getBooktype() {
return booktype;
}
public void setBooktype(String booktype) {
this.booktype = booktype;
}
@Override
public String toString() {
return "Book [id=" + id + ", isbn=" + isbn + ", bookname=" + bookname + ", count=" + count + ", publish=" + publish
+ ", booktype=" + booktype + "]";
}
}
Booktype.java
public class Book {
private Integer id;
private String isbn;
private String bookname;
private Integer count;
private String publish;
private String booktype;
private String author;
public Book() {
super();
// TODO Auto-generated constructor stub
}
public Book(String isbn, String bookname, Integer count, String publish, String booktype, String author) {
super();
this.isbn = isbn;
this.bookname = bookname;
this.count = count;
this.publish = publish;
this.booktype = booktype;
this.author = author;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getBookname() {
return bookname;
}
public void setBookname(String bookname) {
this.bookname = bookname;
}
public Integer getCount() {
return count;
}
public void setCount(Integer count) {
this.count = count;
}
public String getPublish() {
return publish;
}
public void setPublish(String publish) {
this.publish = publish;
}
public String getBooktype() {
return booktype;
}
public void setBooktype(String booktype) {
this.booktype = booktype;
}
@Override
public String toString() {
return "Book [id=" + id + ", isbn=" + isbn + ", bookname=" + bookname + ", count=" + count + ", publish=" + publish
+ ", booktype=" + booktype + "]";
}
}
Borrow.java
public class Borrow {
private Integer id;
private String bar;
private String stuid;
private String stuname;
private String isbn;
private String book;
private String date;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getBar() {
return bar;
}
public void setBar(String bar) {
this.bar = bar;
}
public String getStuid() {
return stuid;
}
public void setStuid(String stuid) {
this.stuid = stuid;
}
public String getStuname() {
return stuname;
}
public void setStuname(String stuname) {
this.stuname = stuname;
}
public String getIsbn() {
return isbn;
}
public void setIsbn(String isbn) {
this.isbn = isbn;
}
public String getBook() {
return book;
}
public void setBook(String book) {
this.book = book;
}
public String getDate() {
return date;
}
public void setDate(String date) {
this.date = date;
}
}
PageBean.java
public class PageBean<T> {
// 当前页
private int pageCode;
// 总页数
// private int totalPage;
// 总记录数
private int totalCount;
// 每页显示的记录条数
private int pageSize;
// 每页显示的数据
private List<T> beanList;
public int getPageCode() {
return pageCode;
}
public void setPageCode(int pageCode) {
this.pageCode = pageCode;
}
/**
* 调用getTotalPage() 获取到总页数
* JavaBean的属性规定:totalPage是JavaBean是属性 ${pageBean.totalPage}
* @return
*/
public int getTotalPage() {
// 计算
int totalPage = totalCount / pageSize;
// 说明整除
if(totalCount % pageSize == 0){
return totalPage;
}else{
return totalPage + 1;
}
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public List<T> getBeanList() {
return beanList;
}
public void setBeanList(List<T> beanList) {
this.beanList = beanList;
}
}
Search.java
public class PageBean<T> {
// 当前页
private int pageCode;
// 总页数
// private int totalPage;
// 总记录数
private int totalCount;
// 每页显示的记录条数
private int pageSize;
// 每页显示的数据
private List<T> beanList;
public int getPageCode() {
return pageCode;
}
public void setPageCode(int pageCode) {
this.pageCode = pageCode;
}
/**
* 调用getTotalPage() 获取到总页数
* JavaBean的属性规定:totalPage是JavaBean是属性 ${pageBean.totalPage}
* @return
*/
public int getTotalPage() {
// 计算
int totalPage = totalCount / pageSize;
// 说明整除
if(totalCount % pageSize == 0){
return totalPage;
}else{
return totalPage + 1;
}
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public List<T> getBeanList() {
return beanList;
}
public void setBeanList(List<T> beanList) {
this.beanList = beanList;
}
}
Dao层的实现方法
AdminDaoImpl.java
public class AdminDaoImpl extends HibernateDaoSupport implements AdminDao {
@Autowired
public void setSessionFactory0(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
public int login(Admin admin) {
// TODO Auto-generated method stub
System.out.println("持久层");
List<Admin> list = (List<Admin>) getHibernateTemplate()
.find("from Admin where username = ? and password = ?",
admin.getUsername(),admin.getPassword());
if(list!=null&&list.size()>0){
return 1;
}else{
return 0;
}
}
@Override
public void changpassoword(String username,String npsw) {
String hql = "update Admin " +
"set password=?" +
" where username=?";
getHibernateTemplate().bulkUpdate(hql,npsw,username);
}
}
BackDaoImpl.java
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import com.zyx.domain.Back;
import com.zyx.domain.Book;
import com.zyx.domain.Borrow;
import com.zyx.domain.PageBean;
@Repository(value = "backDao")
public class BackDaoImpl extends HibernateDaoSupport implements BackDao{
@Autowired
public void setSessionFactory0(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
public PageBean<Back> findByPage(Integer mCurrentPage, Integer pageSize, DetachedCriteria criteria) {
PageBean<Back> pageBean = new PageBean<>();
pageBean.setPageCode(mCurrentPage);
pageBean.setPageSize(pageSize);
criteria.setProjection(Projections.rowCount());
List<Number> list = (List<Number>) getHibernateTemplate().findByCriteria(criteria);
if (list != null&&list.size()>0) {
int totalCount = list.get(0).intValue();
pageBean.setTotalCount(totalCount);
}
criteria.setProjection(null);
@SuppressWarnings("unchecked")
List<Back> customerList = (List<Back>) getHibernateTemplate().findByCriteria(criteria,(mCurrentPage-1)*pageSize,pageSize);
pageBean.setBeanList(customerList);
return pageBean;
// return null;
}
@Override
public List<Book> findallisbn() {
// TODO Auto-generated method stub
return (List<Book>)this.getHibernateTemplate().find("from Book");
}
@Override
public boolean findbar(String bar) {
List<Borrow> list = (List<Borrow>) getHibernateTemplate()
.find("from Borrow where bar = ?",
bar);
if (list != null&&list.size()>0) {
return true;
}else
return false;
}
@Override
public void jiacount(String isbn) {
// TODO Auto-generated method stub
List <Book> booklist=(List<Book>) getHibernateTemplate().find("from Book where isbn=?",isbn);
Book book=booklist.get(0);
book.setCount(book.getCount()+1);
getHibernateTemplate().update(book);
}
@Override
public void deleteborrow(String bar) {
List<Borrow> list = (List<Borrow>) getHibernateTemplate()
.find("from Borrow where bar = ?",
bar);
Borrow borrow=list.get(0);
this.getHibernateTemplate().delete(borrow);
}
@Override
public void addback(Back back) {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(back);
}
}
BlackDaoImpl.java
import java.util.List;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;
import org.springframework.stereotype.Repository;
import com.zyx.domain.Back;
import com.zyx.domain.Book;
import com.zyx.domain.Borrow;
import com.zyx.domain.PageBean;
@Repository(value = "backDao")
public class BackDaoImpl extends HibernateDaoSupport implements BackDao{
@Autowired
public void setSessionFactory0(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
public PageBean<Back> findByPage(Integer mCurrentPage, Integer pageSize, DetachedCriteria criteria) {
PageBean<Back> pageBean = new PageBean<>();
pageBean.setPageCode(mCurrentPage);
pageBean.setPageSize(pageSize);
criteria.setProjection(Projections.rowCount());
List<Number> list = (List<Number>) getHibernateTemplate().findByCriteria(criteria);
if (list != null&&list.size()>0) {
int totalCount = list.get(0).intValue();
pageBean.setTotalCount(totalCount);
}
criteria.setProjection(null);
@SuppressWarnings("unchecked")
List<Back> customerList = (List<Back>) getHibernateTemplate().findByCriteria(criteria,(mCurrentPage-1)*pageSize,pageSize);
pageBean.setBeanList(customerList);
return pageBean;
// return null;
}
@Override
public List<Book> findallisbn() {
// TODO Auto-generated method stub
return (List<Book>)this.getHibernateTemplate().find("from Book");
}
@Override
public boolean findbar(String bar) {
List<Borrow> list = (List<Borrow>) getHibernateTemplate()
.find("from Borrow where bar = ?",
bar);
if (list != null&&list.size()>0) {
return true;
}else
return false;
}
@Override
public void jiacount(String isbn) {
// TODO Auto-generated method stub
List <Book> booklist=(List<Book>) getHibernateTemplate().find("from Book where isbn=?",isbn);
Book book=booklist.get(0);
book.setCount(book.getCount()+1);
getHibernateTemplate().update(book);
}
@Override
public void deleteborrow(String bar) {
List<Borrow> list = (List<Borrow>) getHibernateTemplate()
.find("from Borrow where bar = ?",
bar);
Borrow borrow=list.get(0);
this.getHibernateTemplate().delete(borrow);
}
@Override
public void addback(Back back) {
// TODO Auto-generated method stub
this.getHibernateTemplate().save(back);
}
}
BooklistDaoImpl.java
public class BooklistDaoImpl extends HibernateDaoSupport implements BooklistDao {
@Autowired
public void setSessionFactory0(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
/**
* 分页查询
* @param mCurrentPage
* @param pageSize
* @param criteria
* @return
*/
public PageBean<Book> findByPage(Integer mCurrentPage, Integer pageSize, DetachedCriteria criteria) {
PageBean<Book> pageBean = new PageBean<>();
pageBean.setPageCode(mCurrentPage);
pageBean.setPageSize(pageSize);
criteria.setProjection(Projections.rowCount());
List<Number> list = (List<Number>) getHibernateTemplate().findByCriteria(criteria);
if (list != null&&list.size()>0) {
int totalCount = list.get(0).intValue();
pageBean.setTotalCount(totalCount);
}
criteria.setProjection(null);
List<Book> customerList = (List<Book>) getHibernateTemplate().findByCriteria(criteria,(mCurrentPage-1)*pageSize,pageSize);
pageBean.setBeanList(customerList);
return pageBean;
}
@Override
public void save(Book book) {
this.getHibernateTemplate().save(book);
}
@Override
public List<Booktype> btlist() {
List<Booktype> list = (List<Booktype>) getHibernateTemplate()
.find("from Booktype");
return list;
}
@Override
public boolean findisbn(String isbn) {
List <Book> book=(List<Book>) getHibernateTemplate().find("from Book where isbn=?",isbn);
if(book!=null&&book.size()>0){
return false;
}
else
return true;
}
@Override
public void delete(Book book) {
this.getHibernateTemplate().delete(book);
}
@Override
public Book findbyid(Integer id) {
return (Book)this.getHibernateTemplate().get(Book.class,id);
}
@Override
public boolean findbook(Integer id, String isbn) {
// TODO Auto-generated method stub
List <Book> book=(List<Book>)getHibernateTemplate().find("from Book where isbn=? and id!=?",isbn,id);
if(book!=null&&book.size()>0){
return false;
}else
return true;
}
@Override
public void update(Book book) {
// TODO Auto-generated method stub
this.getHibernateTemplate().update(book);
}
}
BorrowDaoImpl.java
public class BorrowDaoImpl extends HibernateDaoSupport implements BorrowDao {
@Autowired
public void setSessionFactory0(SessionFactory sessionFactory) {
super.setSessionFactory(sessionFactory);
}
@Override
public List<Book> findallisbn() {
return (List<Book>)this.getHibernateTemplate().find("from Book");
}
@Override
public PageBean<Borrow> findByPage(Integer mCurrentPage, Integer pageSize, DetachedCriteria criteria) {
PageBean<Borrow> pageBean = new PageBean<>();
pageBean.setPageCode(mCurrentPage);
pageBean.setPageSize(pageSize);
criteria.setProjection(Projections.rowCount());
List<Number> list = (List<Number>) getHibernateTemplate().findByCriteria(criteria);
if (list != null&&list.size()>0) {
int totalCount = list.get(0).intValue();
pageBean.setTotalCount(totalCount);
}
criteria.setProjection(null);
@SuppressWarnings("unchecked")
List<Borrow> customerList = (List<Borrow>) getHibernateTemplate().findByCriteria(criteria,(mCurrentPage-1)*pageSize,pageSize);
pageBean.setBeanList(customerList);
return pageBean;
}
@Override
public Integer findcount(String isbn) {
List<Book> list = (List<Book>) getHibernateTemplate()
.find("from Book where isbn = ?",
isbn);
return list.get(0).getCount();
}
@Override
public void save(Borrow borrow) {
this.getHibernateTemplate().save(borrow);
}
@Override
public int findbar(String bar) {
List<Borrow> list = (List<Borrow>) getHibernateTemplate()
.find("from Borrow where bar = ?",
bar);
if(list!=null&&list.size()>0){
return 1;
}else{
return 0;
}
}
@Override
public void countjian(String isbn) {
List <Book> booklist=(List<Book>) getHibernateTemplate().find("from Book where isbn=?",isbn);
Book book=booklist.get(0);
book.setCount(book.getCount()-1);
getHibernateTemplate().update(book);
}
}