请教关于ibatis的问题

xiaowang 06-08-21

小弟最近刚学IBATIS,打算用它用它做一个小应用.我是这么使用SQLmap的,不知道对不对,还希望banq给点意见.
先定义一个类用于封装SqlMap初试化程序.
public class BaseIbatisDao{

private static BaseIbatisDao instance = new BaseIbatisDao();
private static Logger log = Logger.getLogger(BaseIbatisDao.class.getName());
protected static final SqlMapClient sqlMap;

static{
try{
log.debug("Attemping to initialize SqlMap!!!");
String resource = "SqlMapConfig.xml";//在WEB-INF/classes目录下查找该文件
Reader reader = Resources.getResourceAsReader(resource);
sqlMap = SqlMapClientBuilder.buildSqlMapClient(reader);
log.debug("Initialized SqlMap!!!");
}catch(Exception e){
log.error("Error intializing BaseIbatisDao!!!", e);
e.printStackTrace();
throw new RuntimeException("Error initializing BaseIbatisDao.class Cause: " + e);
}
}
protected BaseIbatisDao(){

}
public static BaseIbatisDao getInstance(){
return instance;
}

}

接着就在具体类中这么使用:
public class UserBaseIbatisDAOImpl extends BaseIbatisDao implements UserDAO{

Log logger = LogFactory.getLog(this.getClass());

public List getAllUser(){
List user = null;
try{
user = sqlMap.queryForList("User.getAll", null);
}catch(SQLException e){
logger.error("Error getting all User!!!", e);
}
return user;
}

public User getUser(String num){
User user = null;
try{
user = (User)sqlMap.queryForObject("User.getByNum", num);
}catch(SQLException e){
logger.error("Error getting User!!!", e);
}
return user;
}

public void insert(User user){
try{
sqlMap.insert("User.insert", user);
}catch(SQLException e){
logger.error("error inserting User!!!", e);
}
}


}
不知道这样使用什么问题.望大家指点指点.谢谢!

xiaowang
2006-08-21 19:05

大家实际项目中是怎么使用IBATIS,能说说吗?小弟刚入门,希望能得到大家的帮助!

banq
2006-08-23 09:49

不常用,在我的Jpetstore源码中有ibatis使用形式