繁体   English   中英

在groovy中从resources.xml查找bean到控制器/服务

[英]looking up beans from resources.xml into controller/service in groovy

我正在将groovy-grails与jasper报表结合使用来开发应用程序。 我需要根据其参数(例如从数据库中检索到的reportname / id,通过客户点击获取该报告的参数)查找“ report bean”,它将作为resource xml中的report bean的属性存储到reportcontroller或reportservice中。 另外,我还必须“获取”与此ID和参数Map相关的jrxml模板,二者均定义为Bean中的属性。 我需要知道如何实现此目标,以及是否需要在xml中定义用于管理这些报告Bean的任何“管理Bean”。 因此,例如,报告Bean如下所示:

     <bean id="DeptReport" class="com.myapp.reporting.domain.Report">    
        <property name="reportName" value="Dept Report"/>
        <property name="reportFiles">
          <map>
            <entry key="JasperPrint" value="DeptRoles.jrxml"/>
          </map>
        </property>
        <property name="promptforparameter" value="true"/>
        <property name="parameter" value="department_id"/>
        <property name="displayName" value="report.deptReport.name"/>
     </bean>

会有很多这样的豆子。

另外,所有报告的.jrxml文件都存储在目录中,我想将该位置关联到报告上下文中,以便每当在前端单击报告时,我都希望从上下文中将这些值查找到报告服务中/控制器来生成报告。 我知道我们必须在某个地方像ctx.getbean(reportId)一样,但是我也想知道如何使用其他属性(如模板位置,数据源,参数映射,reportid和jasperreportrenderrer对象)设置管理器bean。 因此,每次调用另一个报表时,都会重新使用此ReportManager bean进行加载,并且最好在用户会话中持久保存。

您应该能够执行以下操作:

import org.springframework.context.*

class MyService implements ApplicationContextAware {
  ApplicationContext applicationContext

  def getBeanByName( String name ) {
    applicationContext.getBean( name )
  }
}

这在grails Service类中,但对于控制器也应如此

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM