3. DAO 수정하기
- 기존 SimpleMailDao랑, SimpleMailTemplateDao는 과감히 날려버리고 iBatis를 이용해서 새로이 만들겠다.
- MailDao의 getMailList()메소드와 MailTemplateDao의 getMailTemplateList()가 변경되었으니 유의바란다.
- 여기 샘플은 insert, update, delete, select 모두 구현되어 있는데, 코드 생성기로 구현한거라 그런것일뿐, 실제적으로는 아주 조금만(?) 필요하다.
- 지금에 와서야 고백(?)을 하지만 오라클의 자릿수를 지정하지 않은 Number형은 자바의 Long형의 범위를 벗어나서 BigDecimal이 맞는것이지만, 귀찮은 관계로 Long형을 이용했다. ^^;
01 | package kr.kangwoo.postman.repository; |
06 | import kr.kangwoo.postman.domain.Mail; |
09 | public interface MailDao { |
11 | void insert(Mail mail); |
13 | int update(Mail mail); |
15 | int updateSelective(Mail mail); |
17 | int delete(Long mailNo); |
19 | Mail getMail(Long mailNo); |
21 | List<mail> getList(Map<string, object= "" > parameterMap); |
23 | int count(Map<string, object= "" > parameterMap); |
26 | </string,></string,></mail> |
01 | package kr.kangwoo.postman.repository; |
06 | import kr.kangwoo.postman.domain.MailTemplate; |
09 | public interface MailTemplateDao { |
11 | void insert(MailTemplate mailTemplate); |
13 | int update(MailTemplate mailTemplate); |
15 | int updateSelective(MailTemplate mailTemplate); |
17 | int delete(String templateId); |
19 | MailTemplate getMailTemplate(String templateId); |
21 | List<mailtemplate> getList(Map<string, object= "" > parameterMap); |
23 | int count(Map<string, object= "" > parameterMap); |
26 | </string,></string,></mailtemplate> |
01 | package kr.kangwoo.postman.repository.ibatis; |
06 | import kr.kangwoo.postman.domain.Mail; |
07 | import kr.kangwoo.postman.repository.MailDao; |
09 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; |
12 | public class MailDaoSqlMap extends SqlMapClientDaoSupport implements MailDao { |
14 | public void insert(Mail mail) { |
15 | getSqlMapClientTemplate().insert( "kr.kangwoo.postman.repository.MailDao.insert" , mail); |
18 | public int update(Mail mail) { |
19 | int rows = getSqlMapClientTemplate().update( "kr.kangwoo.postman.repository.MailDao.update" , mail); |
23 | public int updateSelective(Mail mail) { |
24 | int rows = getSqlMapClientTemplate().update( "kr.kangwoo.postman.repository.MailDao.updateSelective" , mail); |
28 | public int delete(Long mailNo) { |
29 | Mail key = new Mail(); |
30 | key.setMailNo(mailNo); |
31 | int rows = getSqlMapClientTemplate().delete( "kr.kangwoo.postman.repository.MailDao.delete" , key); |
35 | public Mail getMail(Long mailNo) { |
36 | Mail key = new Mail(); |
37 | key.setMailNo(mailNo); |
38 | Mail record = (Mail) getSqlMapClientTemplate().queryForObject( "kr.kangwoo.postman.repository.MailDao.getMail" , key); |
42 | @SuppressWarnings ( "unchecked" ) |
43 | public List<Mail> getList(Map<String, Object> parameterMap) { |
44 | List<Mail> records = getSqlMapClientTemplate().queryForList( "kr.kangwoo.postman.repository.MailDao.getList" , parameterMap); |
48 | public int count(Map<String, Object> parameterMap) { |
49 | Integer count = (Integer) getSqlMapClientTemplate().queryForObject( "kr.kangwoo.postman.repository.MailDao.count" , parameterMap); |
01 | package kr.kangwoo.postman.repository.ibatis; |
06 | import kr.kangwoo.postman.domain.MailTemplate; |
07 | import kr.kangwoo.postman.repository.MailTemplateDao; |
09 | import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport; |
12 | public class MailTemplateDaoSqlMap extends SqlMapClientDaoSupport implements MailTemplateDao { |
14 | public void insert(MailTemplate mailTemplate) { |
15 | getSqlMapClientTemplate().insert( "kr.kangwoo.postman.repository.MailTemplateDao.insert" , mailTemplate); |
18 | public int update(MailTemplate mailTemplate) { |
19 | int rows = getSqlMapClientTemplate().update( "kr.kangwoo.postman.repository.MailTemplateDao.update" , mailTemplate); |
23 | public int updateSelective(MailTemplate mailTemplate) { |
24 | int rows = getSqlMapClientTemplate().update( "kr.kangwoo.postman.repository.MailTemplateDao.updateSelective" , mailTemplate); |
28 | public int delete(String templateId) { |
29 | MailTemplate key = new MailTemplate(); |
30 | key.setTemplateId(templateId); |
31 | int rows = getSqlMapClientTemplate().delete( "kr.kangwoo.postman.repository.MailTemplateDao.delete" , key); |
35 | public MailTemplate getMailTemplate(String templateId) { |
36 | MailTemplate key = new MailTemplate(); |
37 | key.setTemplateId(templateId); |
38 | MailTemplate record = (MailTemplate) getSqlMapClientTemplate().queryForObject( "kr.kangwoo.postman.repository.MailTemplateDao.getMailTemplate" , key); |
42 | @SuppressWarnings ( "unchecked" ) |
43 | public List<MailTemplate> getList(Map<String, Object> parameterMap) { |
44 | List<MailTemplate> records = getSqlMapClientTemplate().queryForList( "kr.kangwoo.postman.repository.MailTemplateDao.getList" , parameterMap); |
48 | public int count(Map<String, Object> parameterMap) { |
49 | Integer count = (Integer) getSqlMapClientTemplate().queryForObject( "kr.kangwoo.postman.repository.MailTemplateDao.count" , parameterMap); |
댓글 없음:
댓글 쓰기