将原生 SQL 查询的结果映射到 Grails 域类

编程入门 行业动态 更新时间:2024-10-26 16:24:37
本文介绍了将原生 SQL 查询的结果映射到 Grails 域类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是否可以将本机 SQL 查询的结果映射到 Grails 域类实例的集合?

Is it possible to map the result of a native SQL query to a collection of Grails domain class instances?

推荐答案

import com.acme.domain.* def sessionFactory sessionFactory = ctx.sessionFactory // this only necessary if your are working with the Grails console/shell def session = sessionFactory.currentSession def query = session.createSQLQuery("select f.* from Foo where f.id = :filter)) order by f.name"); query.addEntity(com.acme.domain.Foo.class); // this defines the result type of the query query.setInteger("filter", 88); query.list()*.name;

更多推荐

将原生 SQL 查询的结果映射到 Grails 域类

本文发布于:2023-07-16 04:19:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117764.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:SQL   Grails   域类

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!