spring data jpa 可以把查询结果放到 map 中吗?

oldfeel 发布于 2016/12/10 16:26
阅读 6K+
收藏 1

【开源中国 APP 全新上线】“动弹” 回归、集成大模型对话、畅读技术报告”

sql 语句复杂起来. @Entity 的字段就不够用了.

所以,可以把查询结果放到 map 中吗,记得 jdbc 有个 ResultSet,就是类似的东西.

加载中
0
傻傻躺着
傻傻躺着
可以的 ,返回List<Map<String obect>>
oldfeel
oldfeel
该评论暂时无法显示,详情咨询 QQ 群:点此入群
oldfeel
oldfeel
报错了 @Query(value = "select id from video", nativeQuery = true) List<Map<String, Object>> list(); 我在下面贴错误信息
0
oldfeel
oldfeel

代码


@Query(value = "select id from video",  nativeQuery = true)
List<Map<String, Object>> list();

错误信息

Could not write content: Invalid property 'empty' of bean class [java.lang.Integer]: Could not find field for property during fallback access! (through reference chain: com.yuncommunity.child_star.base.JR[\"data\"]->java.util.ArrayList[0]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Invalid property 'empty' of bean class [java.lang.Integer]: Could not find field for property during fallback access! (through reference chain: com.yuncommunity.child_star.base.JR[\"data\"]->java.util.ArrayList[0])","timeStamp": "Sat Dec 10 17:44:07 CST 2016

0
傻傻躺着
傻傻躺着
<select id="getCountyHashMap" resultType="java.util.HashMap">      select name,id from tsql_test_region where id=#{id} </select>
oldfeel
oldfeel
谢谢,我用的 spring boot,不懂配置. public interface VideoRepository extends JpaRepository<Video, Integer>
-1
傻傻躺着
傻傻躺着
mybatis :<select id="getCountyHashMap" resultType="java.util.HashMap"> select name,id from tsql_test_region where id=#{id} </select>
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部