public interface MemberRepository extends JpaRepository<Member, Long> {
// @Query(name = "Member.findByUsername") 생략 가능
List<Member> findByUsername(@Param("username") String username);
}
public class MemberRepository {
public List<Member> findByUsername(String username) {
...
List<Member> resultList =
em.createNamedQuery("Member.findByUsername", Member.class)
.setParameter("username", username)
.getResultList();
}
}
@Entity
@NamedQuery(
name = "Member.findByUsername",
query = "select m from Member m where m.username = :username")
public class Member {
...
}