public interface UserRepository extends JpaRepository {
@Query(value = "SELECT * FROM USERS WHERE EMAIL_ADDRESS = ?0", nativeQuery = true)
User findByEmailAddress(String emailAddress);
}
Let's say I have the code above where I select * from user. What should I do if I don't want this method to return User object. Is there a way I can manually map the data to a custom object MyUser? Can I do all this in the UserRepository interface?
Thanks!
解决方案
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
最后
以上就是勤奋金毛最近收集整理的关于jpa返回值映射_SpringDataJPA:使用本机查询的自定义数据映射的全部内容,更多相关jpa返回值映射_SpringDataJPA:使用本机查询内容请搜索靠谱客的其他文章。
发表评论 取消回复