使用findAll,List()或SQL Query返回列表中的所有域值

时间:2014-12-22 10:33:24

标签: grails groovy findall

我正在尝试检索所有存在的域值并将它们放入列表中。我正在使用模式对话框来显示此列表,但是目前检索的所有值都只是我正在查看的实例中存在的值,而不是检索数据库中存在的所有值。 / p>

因此,对于每个模板,有许多步骤,即我们正在处理的关系。当我打开模型对话框以检索数据库中的所有步骤时,它只显示该模板上存在的步骤。一些截图可能有助于解释。

包含模态对话框的Show.gsp页面。

<div id="basicModal" title="Existing Template Steps">
    <g:include controller="templateStep" action="renderAllStepsList" />
</div>

控制器 - 而不是使用服务我尝试过TemplateStep.findAll(“来自TemplateStep作为ts”)以及TemplateStep.list(),但它们都具有相同的效果。

def renderAllStepsList(){
    def templateStepInstanceList = TemplateStepService.getSuggestedTemplateSteps() 
    render(template:"list", model: [templateStepInstanceList: templateStepInstanceList])
}

服务

def getSuggestedTemplateSteps() {
    def sql = new Sql(dataSource)
    def rows = sql.rows("select distinct * from template_steps")

    def listOfSteps = rows.collect()

    return listOfSteps
   }
 }

这是目前的模态对话框。如您所见,它向我展示了Template实例中存在的所有步骤,但是我想要检索数据库中存在的所有步骤。这可能吗?

Modal

- 更新 -

模板域类:

   import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty
   import org.codehaus.groovy.grails.commons.GrailsClass

   class Template {

    static notCloneable = ['name']
    static hasMany = [templateSteps:TemplateStep]

    int id
    String name
    String description
    String progressionType
    String defaultPlanType
    String defaultPlanPhase
    String guiFlag
    String extFun

  static mapping = {

    version false
    table 'TEMPLATE'

    id                column: 'SYSID', generator: 'assigned'
    progressionType   column: 'PROGRESSION_TYPE'
    defaultPlanType   column: 'DEFAULT_PLAN_TYPE'
    defaultPlanPhase  column: 'DEFAULT_PLAN_PHASE'
    guiFlag           column: 'GUI_FLAG'
    extFun            column: 'EXT_FUN'
    templateSteps sort :'stepSeq', order:'asc'

}
static constraints = {
    name              (maxSize:250, blank:false, nullable:false, unique:true)
    description       (maxSize:250, blank:true,  nullable:true)
    progressionType   (maxSize:100, blank:true,  nullable:true)
    defaultPlanType   (maxSize:50,  blank:true,  nullable:true) 
    defaultPlanPhase  (maxSize:250, blank:true,  nullable:true) 
    guiFlag           (maxSize:10,  blank:true,  nullable:true)
    extFun            (maxSize:10,  blank:true,  nullable:true)
   }
}

模板步域类:

  import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClassProperty
  import org.codehaus.groovy.grails.commons.GrailsClass

  class TemplateStep {

   static notCloneable = []
   static belongsTo = [template:Template]
   static hasMany =    [templateInput:TemplateInput,templateOutput:TemplateOutput]//,templateOutputTransDisplayMap:TemplateOutputTransDisplayMap,templateInputTransDisplayMap:TemplateInputTransDisplayMap]

  Long id
  String step
  String validationProcedure
  String actionProcedure
  String transactionTable
  String displayLable
  String windowLable
  String cancelProcedure
  String endPlanPhase
  String mfOutFlag
  Long stepSeq
  String swfName

 static mapping = {

    version false
    table'TEMPLATE_STEPS'

    id                  column: 'SYSID', generator: 'assigned'
    template            column: 'MT_SYSID'
    validationProcedure column: 'VALIDATION_PROCEDURE'
    actionProcedure     column: 'ACTION_PROCEDURE'
    transactionTable    column: 'TRANSACTION_TABLE'
    displayLable        column: 'DISPLAY_LABLE'
    windowLable         column: 'WINDOW_LABLE'
    cancelProcedure     column: 'CANCEL_PROCEDURE'
    endPlanPhase        column: 'END_PLAN_PHASE'
    mfOutFlag           column: 'MFOUT_FLAG'
    stepSeq             column: 'STEP_SEQ' 
    swfName             column: 'SWF_NAME'

 }

 static constraints = {
    step                (maxSize:250, blank:false, nullable:false)
    validationProcedure (maxSize:250, blank:true, nullable:true)
    actionProcedure     (maxSize:250, blank:true, nullable:true)
    transactionTable    (maxSize:250, blank:true, nullable:true)
    displayLable        (maxSize:50,  blank:true, nullable:true)
    windowLable         (maxSize:50,  blank:true, nullable:true)
    cancelProcedure     (maxSize:250, blank:true, nullable:true)
    endPlanPhase        (maxSize:30,  blank:true, nullable:true)
    mfOutFlag           (maxSize:30,  blank:true, nullable:true)
    stepSeq             (maxSize:12,  blank:true, nullable:true)
    swfName             (maxSize:100, blank:true, nullable:true)
    template                         (blank:true, nullable:true)
    }
  }

0 个答案:

没有答案