在Grails中的同一查询中使用两个数据库

在Grails中的同一查询中使用两个数据库,grails,datasource,Grails,Datasource,在我的grails应用程序中,我有一个sql查询,它根据另一个数据库中的列从一个数据库中选择列数据。 因此,它在同一查询中与两个数据库交互 是否有一种方法可以根据从另一个数据库检索的数据从一个数据库中拾取数据。 在这样的场景中,您将如何写下代码 思想?找到了解决问题的方法 创建了两个域对象:Cdisc和磁带。 cdisc和磁带是两个不同数据库中的两个表。这两个表都有一个共同的主Id,player_Id。 其思想是在一页上显示这两个表中的数据 Cdisc.groovy package tune

在我的grails应用程序中,我有一个sql查询,它根据另一个数据库中的列从一个数据库中选择列数据。 因此,它在同一查询中与两个数据库交互

是否有一种方法可以根据从另一个数据库检索的数据从一个数据库中拾取数据。 在这样的场景中,您将如何写下代码

思想?

找到了解决问题的方法

创建了两个域对象:Cdisc和磁带。 cdisc和磁带是两个不同数据库中的两个表。这两个表都有一个共同的主Id,player_Id。 其思想是在一页上显示这两个表中的数据

Cdisc.groovy

package tune  

class Cdisc {  
String name  
double cId  
String id  

static mapping = {
    table 'cdisc'  
    version false       

    columns {  
        id column:'player_id'   
        cId column:'c_id'  
        name column: 'name'  
    }  
}  
}  
磁带

package tune

class tape {

    String id   
String tapeDate
String comments 


static mapping = {
    table 'tape'
    version false       
    columns {       
        id column:'player_id'       
         tapeDate column:'tape_date'
         comments column: 'comments'
}

}



public def getName(){       
    def cdisc = Cdisc.findById(this.id)     
    return cdisc.name
}

}
TapeController.groovy

def list = {
    params.max = Math.min(params.max ? params.int('max') : 10, 100)

    [tapeInstanceList: tape.findAllByCommentsLike('%Test%'),     tapeInstanceTotal: Tape.count()]

}
最后使用getter显示表cdisc中的名称

普惠制

    <g:each in="${tapeInstanceList}" status="i"
        var="tapeInstance">
        <tr class="${(i % 2) == 0 ? 'odd' : 'even'}">

            <td><g:link action="edit" id="${tapeInstance.id}">
                ${fieldValue(bean: tapeInstance, field: "id")}
            </g:link></td>

            <td>
            ${fieldValue(bean: tapeInstance, field: "tapeDate")}
            </td>

            <td>
            ${fieldValue(bean: tapeInstance, field: "comments")}
            </td>

             <td>${tapeInstance.getName()}</td>


    </g:each>
因此,我们使用getter从另一个数据库的第二个表中获取数据。 为我工作。如果还有其他解决办法,请告诉我