The Spring framework supports iBATIS using a template pattern for the data access objects, meanig that you start with an existing Spring class(SqlMapClient Template) and extend it for your DAO. using this technique, our AccountDao implementation would look like below example using Spring.
public class AccountDaoImplSpring extends SqlMapClientTemplate implements AccountDao
{
public Integer insert(Account account) {
return (Integer) insert("Account.insert", account);
}
public int update(Account account) {
return update("Account.update", account);
}
public int delete(Account account) {
return delete(account.getAccountId());
}
public int delete(Integer accountId) {
return delete("Account.delete", accountId);
}
public List<Account> getAccountListByExample(
Account account) {
return queryForList("Account.getAccountListByExample", account);
}
public List<Map<String, Object>>
getMapListByExample(Account account) {
return queryForList("Account.getMapListByExample", account);
}
public List<IdDescription>
getIdDescriptionListByExample(Account account) {
return
queryForList("Account.getIdDescriptionListByExample", account);
}
public Account getById(Integer accountId) {
return (Account) queryForObject("Account.getById", accountId);
}
public Account getById(Account account) {
return (Account) queryForList("Account.getById", account);
}
}
Why use Spring instead of iBATIS?
The big advantage of Spring is that it is not only for DAO classes but for all segments of your application.
public class AccountDaoImplSpring extends SqlMapClientTemplate implements AccountDao
{
public Integer insert(Account account) {
return (Integer) insert("Account.insert", account);
}
public int update(Account account) {
return update("Account.update", account);
}
public int delete(Account account) {
return delete(account.getAccountId());
}
public int delete(Integer accountId) {
return delete("Account.delete", accountId);
}
public List<Account> getAccountListByExample(
Account account) {
return queryForList("Account.getAccountListByExample", account);
}
public List<Map<String, Object>>
getMapListByExample(Account account) {
return queryForList("Account.getMapListByExample", account);
}
public List<IdDescription>
getIdDescriptionListByExample(Account account) {
return
queryForList("Account.getIdDescriptionListByExample", account);
}
public Account getById(Integer accountId) {
return (Account) queryForObject("Account.getById", accountId);
}
public Account getById(Account account) {
return (Account) queryForList("Account.getById", account);
}
}
Why use Spring instead of iBATIS?
The big advantage of Spring is that it is not only for DAO classes but for all segments of your application.
Comments
Post a Comment