我直接在A类中的main实例化A类后调用B类的静态方法可以,如果是在某gsp页面实例化A类,在调用B类的静态方法就出错,我在B类中的那个静态方法里使用了反射,以下是代码
SysContext.groovy
Groovy代码
package cn.aloxc.stock.context
import cn.aloxc.stock.*;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
public class SysContext {
public static void main(def args)
{
println getPrpt("BOYI_PERIOD");
}
public static getPrpt(def a)
{
Class clazz = Class.forName("cn.aloxc.stock.context.SysContext");
def field = clazz.getField("${a.toUpperCase()}");
def property = field.get(clazz);
return property;
}
public static BOYI_PERIOD = ["day","week","month","season"];
}
XlsExportService .groovy
Groovy代码
package cn.aloxc.stock.tools;
import cn.aloxc.stock.*;
import cn.aloxc.stock.context.SysContext;
class XlsExportService {
public static void main(def args)
{
def domains = ["cn.aloxc.stock.Zcggstat","cn.aloxc.stock.Boyistat","cn.aloxc.stock.Fundstat"]
me.xlsExportData(null,null,domains)
}
def xlsExportData(out, request, domains){
domains.eachWithIndex{domain ,dmnIdx ->
def smpDmn = domain.replaceAll("${SysContext.DOMAIN_ROOT}.","").toLowerCase(); //eg:zcggstat
SysContext.getPrpt("${BOYI_PERIOD}").eachWithIndex{ aTp , aIdx ->
//
}
}
}
xx.gsp
<%@ page import="cn.aloxc.stock.tools.XlsExportService" %>
<%
XlsExportService xlsExportService = new XlsExportService();
//response.setHeader("Content-disposition", "attachment; filename=boyistat.xls")
//response.setContentType("application/vnd.ms-excel")
def domains = [];
grailsApplication.domainClasses.each{
domains << it.fullName;
}
xlsExportService.xlsExportData(response.outputStream, request,domains);
%>
省去了部分代码,不知道大家有碰到这样的问题否
分享到:
相关推荐
Grails参考手册 Grails学习资料 groovy 小白学习grails+groovy
eclipse插件grails(groovy)配置方法
0,下载Grails( http://dist.codehaus.org/grails/grails-bin-0.4.2.zip ,请留意朝花夕拾——Groovy & Grails中的“最新版本”提示)并解压到自己指定位置(我的位置是D:\D\MY_DEV\grails) 1,设置环境变量GRAILS...
Grails Groovy 学习必备参考资料
脚本通过上下文applicationcontext获取被测试应用bean,从而可以进行接口内容获取等操作。目前该方式主要运用到性能平台脚本搭建、代码深度测试、接口测试、白盒测试等多方面。...支持Java、groovy脚本。
Groovy和Grails配置方法 教你从0入手,一步一步深入安装和测试,包含环境和语言的下载地址
Groovy / Grails F2 The Best Web Server
Groovy / Grails F4 The Best Web Server
Groovy / Grails F3 The Best Web Server
NULL 博文链接:https://bluedest.iteye.com/blog/759361
NULL 博文链接:https://bluedest.iteye.com/blog/759400
You'll see how to harness Gradle (Groovy's build system), Grails (Groovy's web application framework), Spock (Groovy's testing framework), and Ratpack (Groovy's reactive web library). What You Will ...
NULL 博文链接:https://bluedest.iteye.com/blog/759403
NULL 博文链接:https://bluedest.iteye.com/blog/759370