기존 코드 (람다 RowMapper)
// 아이디로 PK 조회 (주문, 장바구니, 주소 등 FK 연결용)
else if ("SELECT_ACCOUNT_PK_BY_ACCOUNT_ID".equals(accountDTO.getCondition())) {
System.out.println("[로그] AccountRepository의 SELECT_ACCOUNT_PK_BY_ACCOUNT_ID");
return jdbcTemplate.queryForObject(
SELECT_ACCOUNT_PK_BY_ACCOUNT_ID,
(rs, rowNum) -> {
AccountDTO dto = new AccountDTO();
dto.setAccountPk(rs.getInt("accountPk"));
return dto;
},
accountDTO.getAccountId()
);
}
BeanPropertyRowMapper로 줄인 버전
return jdbcTemplate.queryForObject(
SELECT_ACCOUNT_PK_BY_ACCOUNT_ID,
new BeanPropertyRowMapper<>(AccountDTO.class),
accountDTO.getAccountId()
);
⚠️ 주의할 점 딱 하나
- 컬럼 AS 이름 = DTO 필드명
- 대소문자 상관 없음
- 스네이크 → 카멜 자동 변환도 해줌
'🎅 오너먼트 프로젝트' 카테고리의 다른 글
| DTO 멤버변수 타입 래퍼타입으로 일치시키기 (0) | 2026.02.14 |
|---|---|
| 자바와 쿼리문이 합쳐져 있던 Repository 파일 MyBatis로 결합도 낮춰보기 (0) | 2026.02.11 |
| BeanPropertyRowMapper로 자동 매칭 (0) | 2026.02.07 |
| 테이블 이관 작업 진행 (Oracle ➡️ Mysql) (0) | 2026.02.01 |
| 🛠️ Eclipse Database Connections 설정 (MySQL) (0) | 2026.01.30 |