SpringDataJPA: custom data mapping with Native Query

前端 未结 2 808
被撕碎了的回忆
被撕碎了的回忆 2021-02-19 19:35
public interface UserRepository extends JpaRepository {

  @Query(value = \"SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?0\", nativeQuery = true)
  User          


        
2条回答
  •  深忆病人
    2021-02-19 20:37

    You can do something like this

    @Query(value = "SELECT YOUR Column1, ColumnN FROM USERS WHERE EMAIL_ADDRESS = ?0", nativeQuery = true)
    List findByEmailAddress(String emailAddress);
    

    You have to do the mapping. Take a look at the Spring Data Repository as well. Source

提交回复
热议问题