系统原型结构描述(十)
来源:互联网 发布:java 读取文件绝对路径 编辑:程序博客网 时间:2024/06/05 16:26
Book.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMap
PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="Book">
<!-- Use type aliases to avoid typing the full classname every time. -->
<typeAlias alias="Book" type="com.test.domain.Book"/>
<!-- Result maps describe the mapping between the columns returned
from a query, and the class properties. A result map isn't
necessary if the columns (or aliases) match to the properties
exactly. -->
<resultMap id="BookResult" class="Book">
<result property="id" column="ID"/>
<result property="name" column="NAME"/>
<result property="author" column="AUTHOR"/>
<result property="summary" column="SUMMARY"/>
</resultMap>
<!-- Select with no parameters using the result map for Account class. -->
<select id="SelectAllBooks" resultMap="BookResult">
select * from BOOKS
</select>
<select id="GetBookTotal" resultClass="int">
select count(id) from BOOKS
</select>
<!-- A simpler select example without the result map. Note the
aliases to match the properties of the target result class. -->
<select id="SelectBookById" parameterClass="int" resultClass="Book">
select * from BOOKS
where ID = #id#
</select>
<select id="SelectBookByname" parameterClass="String" resultMap="BookResult">
select * from BOOKS
where NAME = #name#
</select>
<!-- Insert example, using the Account parameter class -->
<insert id="InsertBook" parameterClass="Book">
insert into BOOKS (
ID,
NAME,
AUTHOR,
SUMMARY)
values (
#id#, #name#, #author#, #summary#
)
</insert>
<!-- Update example, using the Account parameter class -->
<update id="UpdateBook" parameterClass="Book">
update BOOKS set
NAME = #name#,
AUTHOR = #author#,
SUMMARY = #summary#
where
ID = #id#
</update>
<!-- Delete example, using an integer as the parameter class -->
<delete id="DeleteBookById" parameterClass="int">
delete from BOOKS where ID = #id#
</delete>
</sqlMap>
Config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE sqlMapConfig
PUBLIC "-//ibatis.apache.org//DTD SQL Map Config 2.0//EN"
"http://ibatis.apache.org/dtd/sql-map-config-2.dtd">
<sqlMapConfig>
<!-- List the SQL Map XML files. They can be loaded from the
classpath, as they are here (com.domain.data...) -->
<sqlMap resource="com/test/persistence/Book.xml"/>
</sqlMapConfig>
BookDao.java
package com.test.persistence.dao.impl;
import java.util.List;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.test.domain.Book;
import com.test.persistence.dao.IBookDao;
public class BookDao implements IBookDao {
private SqlMapClientTemplate sqlMapClientTemplate = null;
public SqlMapClientTemplate getSqlMapClientTemplate() {
return sqlMapClientTemplate;
}
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) {
this.sqlMapClientTemplate = sqlMapClientTemplate;
}
public List selectAllBooks(int top, int max) {
return this.sqlMapClientTemplate.queryForList("SelectAllBooks", top, max);
}
public int getBookTotal() {
return ((Integer)this.sqlMapClientTemplate.queryForObject
("GetBookTotal")).intValue();
}
public Book selectBookById(int id) {
return (Book) this.sqlMapClientTemplate.queryForObject("SelectBookById", new
Integer(id));
}
public List selectBookByName(String name) {
return this.sqlMapClientTemplate.queryForList("SelectBookByname", name);
}
public void insertBook(Book book) {
this.sqlMapClientTemplate.insert("InsertBook", book);
}
public void updateBook(Book book) {
this.sqlMapClientTemplate.update("UpdateBook", book);
}
public void deleteBookById(int id) {
this.sqlMapClientTemplate.delete("DeleteBookById", new Integer(id));
}
}
PageManager.java
package com.test.page;
public class PageManager {
private IPage page = null;
private IPageResult pageResult = null;
public IPage getPage() {
return page;
}
public void setPage(Page page) {
this.page = page;
}
public IPageResult getPageResult() {
return pageResult;
}
public void setPageResult(PageResult pageResult) {
this.pageResult = pageResult;
}
public PageValue run(PageValue value) {
value.setRecords(this.pageResult.getTotal());
value = this.page.run(value);
value = this.pageResult.run(value);
return value;
}
}
PageResult.java
package com.test.page;
import java.util.List;
import org.apache.log4j.Logger;
import com.test.persistence.dao.impl.BookDao;
public class PageResult implements IPageResult {
static final Logger logger = Logger.getLogger(PageResult.class);
private BookDao bookDao = null;
public PageValue run(PageValue value) {
//value.setRecords(this.getTotal());
value.setResult(this.getResult(value.getTop(), value.getMax()));
logger.debug("Page : Total record " + value.getRecords());
logger.debug("Page : Result " + value.getResult());
return value;
}
public BookDao getBookDao() {
return bookDao;
}
public void setBookDao(BookDao bookDao) {
this.bookDao = bookDao;
}
public int getTotal() {
return this.bookDao.getBookTotal();
}
public List getResult(int top, int max){
return this.bookDao.selectAllBooks(top, max);
}
}
- 系统原型结构描述(十)
- 系统原型结构描述(三)
- 系统原型结构描述(四)
- 系统原型结构描述(五)
- 系统原型结构描述(六)
- 系统原型结构描述(七)
- 系统原型结构描述(八)
- 系统原型结构描述(九)
- 系统原型结构描述(十一)
- 系统原型结构描述(十二)
- 系统原型结构描述(一)系统原型开发包目录结构清单
- 系统原型结构描述(二)系统原型开发包说明
- 系统原型结构描述(概述)最近要设计一个框架,大家一起讨论下如何实现?
- 描述符相关的几个系统结构
- 原型模式--java描述
- 数据结构 JAVA描述(十) 交换排序
- Linux下IP协议使用的地址描述数据结构结构的典型原型声明
- 系统进程描述(转载)
- 防止内存泄露 Linux下用Valgrind做检查
- 在Sharepoint中使用Infopath form service
- GridView使用心得
- XIR2 BOE 上RAS无法启动
- cygwin是一个在windows平台上运行的unix模拟环境
- 系统原型结构描述(十)
- SQL Server中的布尔类型Bit
- 排序链树搜索算法在GIS POI关键字搜索中的应用
- ASP.NET常用的26个优化性能方法
- SQL Server 2000中的数据转换服务 (DTS)
- Take a glance of Firefox extension(火狐狸扩展插件一瞥)
- GridView 显示数据,在页脚添加合计
- Oracle查看数据库空间使用情况
- 羊皮卷第一卷