我是靠谱客的博主 勤奋金毛,最近开发中收集的这篇文章主要介绍jpa返回值映射_SpringDataJPA:使用本机查询的自定义数据映射,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

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:使用本机查询的自定义数据映射所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(58)

评论列表共有 0 条评论

立即
投稿
返回
顶部