我正在尝试使用native query
来返回表格中某个column
的值。
我知道原生查询可用于返回对象,即在此示例中?:
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?1", nativeQuery = true)
User findByEmailAddress(String emailAddress);
}
但是,如何写这个以返回一列的值?即如果我只想返回用户的名称(字符串),不
用户object
?
答案 0 :(得分:5)
试试这个:
public interface UserRepository extends JpaRepository<User, Long> {
@Query(value = "SELECT u.name FROM USERS u WHERE EMAIL_ADDRESS = ?1", nativeQuery = true)
String findByEmailAddress(String emailAddress);
}