@OverridepublicOptional<Member>findByName(Long id) {List<Member> result =jdbcTemplate.query("select * from member where name = ?",memberRowMapper(), id);returnresult.stream().findAny();}
findByName
@OverridepublicOptional<Member>findByName(String name) {List<Member> result =jdbcTemplate.query("select * from member where name = ?",memberRowMapper(), name);returnresult.stream().findAny();}
findAll
@OverridepublicList<Member>findAll() {//sql 결과를 리스트로 반환. resultset결과를 memberRowMapper()에서 객체로 맵핑.returnjdbcTemplate.query("select * from member",memberRowMapper());//객체 생성에 대한 것은 밑에서 콜백으로 정의.}
RowMapper : 쿼리문을 작성해서 그 결과를 받아올 때 RowMapper로 객체를 맵핑시켜서 받는다!
private RowMapper<Member> memberRowMapper(){
//람다로 바꿀 수 있음!옵션 + 엔터
//jdbc
return (rs, rowNum) -> {
Member member = new Member();
member.setId(rs.getLong("id"));
member.setName(rs.getString("name"));
return member;
};
}