?? bookdao.java
字號:
package com.dao;
import java.io.Reader;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.common.resources.Resources;
import com.ibatis.sqlmap.engine.builder.xml.XmlSqlMapClientBuilder;
import com.actionForm.BookForm;
import java.sql.SQLException;
import com.tool.DealwithString;
import java.util.List;
public class BookDao {
public SqlMapClient sqlMap;
public void getSqlMapClient() {
try {
String resource = "DataAccess.xml";
Reader reader = Resources.getResourceAsReader(resource);
XmlSqlMapClientBuilder xmlBuilder = new XmlSqlMapClientBuilder();
sqlMap = xmlBuilder.buildSqlMap(reader);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Error initializing SqlConfig. Cause: " +
e);
}
}
//自動編號的方法
public String selectMaxIdBook() {
String book = null;
BookForm form = null;
try {
this.getSqlMapClient();
sqlMap.startTransaction();
form = (BookForm) sqlMap.queryForObject("selectMaxIdBook", null);
} catch (SQLException ex) {
}
if (form != null) {
book = form.getBookNumber();
}
book = DealwithString.maxNumberString(book, "BOOK-", 5);
return book;
}
//添加圖書信息的方法
public boolean insertBook(BookForm bookForm) {
try {
this.getSqlMapClient();
sqlMap.startTransaction();
sqlMap.insert("insertBook", bookForm);
sqlMap.commitTransaction();
return true;
} catch (SQLException ex) {
return false;
}
}
//全部查詢,分頁顯示
public List selectBook(int number) {
List list = null;
try {
this.getSqlMapClient();
sqlMap.startTransaction();
list = sqlMap.queryForList("selectBookForm", null, number * 14,
14);
} catch (SQLException ex) {
}
return list;
}
/**通過FORM把值傳遞到(updateBook.jsp)頁面
* 通過一個bookNumber把數據庫的相應記錄查詢出來
* @param bookSortForm
* @return
*/
public BookForm selectBook(BookForm bookSortForm) {
BookForm form = null;
try {
this.getSqlMapClient();
sqlMap.startTransaction();
form = (BookForm) sqlMap.queryForObject("selectBookForm",
bookSortForm);
} catch (SQLException ex) {
}
return form;
}
//查詢出多少條紀錄
public int selectBook() {
List list = null;
try {
this.getSqlMapClient();
sqlMap.startTransaction();
list = sqlMap.queryForList("selectBookForm", null);
} catch (SQLException ex) {
}
int number = list.size();
if (number % 14 == 0) {
number = number / 14;
} else {
number = number / 14 + 1;
}
return number;
}
//以圖書名稱為條件,刪除一組數據
public boolean deleteBook(BookForm bookForm) {
try {
this.getSqlMapClient();
sqlMap.delete("deleteBook", bookForm);
return true;
} catch (SQLException ex) {
return false;
}
}
//修改圖書信息的方法
public boolean updateBook(BookForm bookForm) {
try {
this.getSqlMapClient();
sqlMap.insert("updateBook", bookForm);
return true;
} catch (SQLException ex) {
return false;
}
}
//修改圖書數目
public boolean addBook(BookForm bookForm) {
try {
this.getSqlMapClient();
sqlMap.insert("addBook", bookForm);
return true;
} catch (SQLException ex) {
return false;
}
}
//全部查詢
public List selectBookAll() {
List list = null;
try {
this.getSqlMapClient();
sqlMap.startTransaction();
list = sqlMap.queryForList("selectBookForm", null);
} catch (SQLException ex) {
}
return list;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -