浏览 7982 次
精华帖 (0) :: 良好帖 (1) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2012-02-01
最后修改:2012-02-01
老org.apache.ibatis.session.SqlSession接口方法 Object selectOne(String statement); Object selectOne(String statement, Object parameter); List selectList(String statement); List selectList(String statement, Object parameter); List selectList(String statement, Object parameter, RowBounds rowBounds); 新org.apache.ibatis.session.SqlSession接口方法 /** * Retrieve a single row mapped from the statement key * @param <T> the returned object type * @param statement * @return Mapped object */ <T> T selectOne(String statement); /** * Retrieve a single row mapped from the statement key and parameter. * @param <T> the returned object type * @param statement Unique identifier matching the statement to use. * @param parameter A parameter object to pass to the statement. * @return Mapped object */ <T> T selectOne(String statement, Object parameter); /** * Retrieve a list of mapped objects from the statement key and parameter. * @param <E> the returned list element type * @param statement Unique identifier matching the statement to use. * @return List of mapped object */ <E> List<E> selectList(String statement); /** * Retrieve a list of mapped objects from the statement key and parameter. * @param <E> the returned list element type * @param statement Unique identifier matching the statement to use. * @param parameter A parameter object to pass to the statement. * @return List of mapped object */ <E> List<E> selectList(String statement, Object parameter); /** * Retrieve a list of mapped objects from the statement key and parameter, * within the specified row bounds. * @param <E> the returned list element type * @param statement Unique identifier matching the statement to use. * @param parameter A parameter object to pass to the statement. * @param rowBounds Bounds to limit object retrieval * @return List of mapped object */ <E> List<E> selectList(String statement, Object parameter, RowBounds rowBounds); 对比了一下,这种返回方式在mybatis的spring支持包mybatis-spring-1.0.0-RC2-bundle中出现过,当时,这个包中的SqlSessionTemplate是这么定义的: SqlSessionTemplate extends JdbcAccessor implements SqlSessionOperations 再看看SqlSessionOperations接口 package org.mybatis.spring; import java.util.List; import org.apache.ibatis.session.ResultHandler; import org.apache.ibatis.session.RowBounds; public interface SqlSessionOperations { /** * @see org.apache.ibatis.session.SqlSession#selectOne(String) * @throws org.springframework.dao.DataAccessException in case of errors */ Object selectOne(String statement); /** * @see org.apache.ibatis.session.SqlSession#selectOne(String, Object) * @throws org.springframework.dao.DataAccessException in case of errors */ Object selectOne(String statement, Object parameter); /** * @see org.apache.ibatis.session.SqlSession#selectList(String, Object) * @throws org.springframework.dao.DataAccessException in case of errors */ <T> List<T> selectList(String statement); /** * @see org.apache.ibatis.session.SqlSession#selectList(String, Object) * @throws org.springframework.dao.DataAccessException in case of errors */ <T> List<T> selectList(String statement, Object parameter); /** * @see org.apache.ibatis.session.SqlSession#selectList(String, Object, org.apache.ibatis.session.RowBounds) * @throws org.springframework.dao.DataAccessException in case of errors */ <T> List<T> selectList(String statement, Object parameter, RowBounds rowBounds); // /** // * @see org.apache.ibatis.session.SqlSession#selectMap(String statement, String mapKey) // * @throws org.springframework.dao.DataAccessException in case of errors // */ // <K, T> Map<K, T> selectMap(String statement, String mapKey); // // /** // * @see org.apache.ibatis.session.SqlSession#selectMap(String statement, Object parameter, String mapKey) // * @throws org.springframework.dao.DataAccessException in case of errors // */ // <K, T> Map<K, T> selectMap(String statement, Object parameter, String mapKey); // // /** // * @see org.apache.ibatis.session.SqlSession#selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds) // * @throws org.springframework.dao.DataAccessException in case of errors // */ // <K, T> Map<K, T> selectMap(String statement, Object parameter, String mapKey, RowBounds rowBounds); /** * @see org.apache.ibatis.session.SqlSession#select(String, Object, org.apache.ibatis.session.ResultHandler) * @throws org.springframework.dao.DataAccessException in case of errors */ void select(String statement, Object parameter, ResultHandler handler); /** * @see org.apache.ibatis.session.SqlSession#select(String, org.apache.ibatis.session.ResultHandler) * @throws org.springframework.dao.DataAccessException in case of errors */ void select(String statement, ResultHandler handler); /** * @see org.apache.ibatis.session.SqlSession#select(String, Object, org.apache.ibatis.session.RowBounds, org.apache.ibatis.session.ResultHandler) * @throws org.springframework.dao.DataAccessException in case of errors */ void select(String statement, Object parameter, RowBounds rowBounds, ResultHandler handler); /** * @see org.apache.ibatis.session.SqlSession#insert(String) * @throws org.springframework.dao.DataAccessException in case of errors */ int insert(String statement); /** * @see org.apache.ibatis.session.SqlSession#insert(String, Object) * @throws org.springframework.dao.DataAccessException in case of errors */ int insert(String statement, Object parameter); /** * @see org.apache.ibatis.session.SqlSession#update(String) * @throws org.springframework.dao.DataAccessException in case of errors */ int update(String statement); /** * @see org.apache.ibatis.session.SqlSession#update(String, Object) * @throws org.springframework.dao.DataAccessException in case of errors */ int update(String statement, Object parameter); /** * @see org.apache.ibatis.session.SqlSession#delete(String) * @throws org.springframework.dao.DataAccessException in case of errors */ int delete(String statement); /** * @see org.apache.ibatis.session.SqlSession#delete(String, Object) * @throws org.springframework.dao.DataAccessException in case of errors */ int delete(String statement, Object parameter); /** * @see org.apache.ibatis.session.SqlSession#getMapper(Class) * @throws org.springframework.dao.DataAccessException in case of errors */ <T> T getMapper(Class<T> type); } 可惜后来的mybatis-spring版本中的SqlSessionTemplate类改为实现SqlSession接口,因为Mybatis3.0.X的SqlSession接口selectList方法返回的是原始的List,导至每次调用都要强制转换,现在Mybatis3.1将SqlSession接口的selectList方法改为泛型,自然再调用SqlSessionTemplate将不再需要做强制转换了。期待release版本早点出来。 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2012-02-02
挺用心的
自从接触了模型驱动的思想后,dao这层的设计,已经想转用hibernate了 |
|
返回顶楼 | |
发表时间:2012-02-02
感谢楼主的分享,这个帖子很有用。
|
|
返回顶楼 | |
发表时间:2012-02-08
总体来说,我觉得相对于ibatis ,mybatis用起来好像跟方便了一些,个人觉得!
|
|
返回顶楼 | |