[Grails] grails、grails、java?bug
leero
2009-10-14
我直接在A类中的main实例化A类后调用B类的静态方法可以,如果是在某gsp页面实例化A类,在调用B类的静态方法就出错,我在B类中的那个静态方法里使用了反射,以下是代码
SysContext.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"]; public static DOMAIN_ROOT = "cn.aloxc.stock"; } Servs.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("$ZCGG_ATYPE").eachWithIndex{ aTp , aIdx -> // } } } |
|
leero
2009-10-14
<%@ 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); %> |
|
leero
2009-10-14
省去了部分代码,不知道大家有碰到这样的问题否
|