本系统由java+sevlet+mysql+eclipse实现的Java web图书管理系统,具有增删改查以及导出Excel表格的功能,需要源码或者需要定制类似的Java /Java web/ ssm/spring boot小型系统,如果需要讲解项目、远程部署,可以加我QQ1728608455,希望能帮助大家,
关注我的公众哈,送iT视频资料和Java web源码,希望能帮到你;
1、效果图
2、实体类
public class Book {
private Integer number;
public Integer getNumber() {
return number;
}
public void setNumber(Integer number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getNum() {
return num;
}
public void setNum(Integer num) {
this.num = num;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
private String name;
private Integer num;
private String author;
public Date getAddTime() {
return addTime;
}
public void setAddTime(Date addTime) {
this.addTime = addTime;
}
private Date addTime;
}
3、Dao层
package mapper;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import entity.Book;
import utils.DBConnection;
public class BookMapper {
public List
List
Connection conn = DBConnection.getConnectDb();
String sql = "select * from book";
PreparedStatement stm = null;
ResultSet rs = null;
try {
stm = conn.prepareStatement(sql);
rs = stm.executeQuery();
while(rs.next()){
Book tag = new Book();
tag.setNumber(rs.getInt("number"));
tag.setName(rs.getString("name"));
tag.setNum(rs.getInt("num"));
tag.setAuthor(rs.getString("author"));
tag.setAddTime(rs.getDate("addTime"));
list.add(tag);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBConnection.CloseDB(rs, stm, conn);
}
return list;
}
public boolean insert(Book book){
Connection conn = DBConnection.getConnectDb();
String sql = "insert into book(number,name,num,author,addTime) values(?,?,?,?,?)";
int rs = 0;
PreparedStatement stm = null;
try{
PreparedStatement pst=conn.prepareStatement(sql);
pst.setInt(1,book.getNumber());
pst.setString(2, book.getName());
pst.setInt(3, book.getNum());
pst.setString(4, book.getAuthor());
pst.setDate(5, book.getAddTime());
pst.execute();
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}finally{
//DBConnection.CloseDB(rs, stm, conn);
}
}
public boolean update(Book book,int number) {
Connection conn=null;
PreparedStatement stm=null;
ResultSet rs=null;
try{
conn=DBConnection.getConnectDb();
String sql="update book set number=?,name=?,num=?,author=?,addTime where number=?";
stm=conn.prepareStatement(sql);
stm.setInt(1, book.getNumber());
stm.setString(2,book.getName());
stm.setInt(3, book.getNum());
stm.setString(4, book.getAuthor());
stm.setDate(5, book.getAddTime());
stm.setInt(6,number);
stm.execute();
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}finally{
DBConnection.CloseDB(rs, stm, conn);
}
}
public List
Connection conn=null;
List
ResultSet rs=null;
PreparedStatement stm=null;
try{
conn=DBConnection.getConnectDb();
String sql="select * from Book where number=?";
stm=conn.prepareStatement(sql);
stm.setInt(1, number);
rs=stm.executeQuery();
while(rs.next()) {
Book tag =new Book();
tag.setNumber(rs.getInt("number"));
tag.setName(rs.getString("name"));
tag.setNum(rs.getInt("num"));
tag.setAuthor(rs.getString("author"));
tag.setAddTime(rs.getDate("addTime"));
list.add(tag);
}
return list;
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
DBConnection.CloseDB(rs,stm,conn);
}
}
public Book queryByNumber(int number){
Connection conn=null;
PreparedStatement stm=null;
ResultSet rs=null;
try{
conn=DBConnection.getConnectDb();
String sql="select * from book where number=?";
stm=conn.prepareStatement(sql);
stm.setInt(1,number);
rs=stm.executeQuery();
if(rs.next()){
Book tag =new Book();
tag.setNumber(rs.getInt("number"));
tag.setName(rs.getString("name"));
tag.setNum(rs.getInt("num"));
tag.setAuthor(rs.getString("author"));
tag.setAddTime(rs.getDate("addTime"));
return tag;
}else{
return null;
}
}catch(Exception e){
e.printStackTrace();
return null;
}finally{
DBConnection.CloseDB(rs,stm,conn);
}
}
public boolean delete( int number) {
Connection conn=null;
PreparedStatement stm=null;
ResultSet rs=null;
try{
conn=DBConnection.getConnectDb();
String sql="delete from book where number=?";
PreparedStatement pst=conn.prepareStatement(sql);
pst.setInt(1,number);
pst.execute();
return true;
}catch(Exception e){
e.printStackTrace();
return false;
}finally{
DBConnection.CloseDB(rs,stm,conn);
}
}
}
希望能帮到大家。