alibaba / QLExpress

QLExpress is a powerful, lightweight, dynamic language for the Java platform aimed at improving developers’ productivity in different business scenes.
Apache License 2.0
4.8k stars 1.13k forks source link

不定参数问题 #349

Open hvne4j opened 3 weeks ago

hvne4j commented 3 weeks ago

版本 3.3.3

除了不定参数,如果还有别的参数,就会报错

public void testMethodReplace() throws Exception { ExpressRunner runner = new ExpressRunner(); IExpressContext<String,Object> expressContext = new DefaultContext<String,Object>(); runner.addFunctionOfServiceMethod("getTemplate", this, "getTemplate", new Class[]{String[].class}, null);

    //(2)像java一样,支持函数动态参数调用,需要打开以下全局开关,否则以下调用会失败
    DynamicParamsUtil.supportDynamicParams = true;
    Object r = runner.execute("getTemplate('哈哈哈', '11','22', '33')", expressContext, null,false, false);
    System.out.println(r);
}
//等价于getTemplate(Object[] params)
public String getTemplate(String name, String... params) throws Exception{
    String result = name + ",";
    for(String obj:params){
        result = result+obj+",";
    }
    return result;
}
DQinYuan commented 3 weeks ago

image

函数签名传递的不对

hvne4j commented 3 weeks ago

请教一下,为什么我运行这个就会找不到方法呢? 20240829094654

image

public static void main(String[] args) throws Exception { DataSource ds = DataSourceUtil.build("com.zaxxer.hikari.HikariDataSource", "com.mysql.cj.jdbc.Driver", "xxx", "xxx", "xxx"); ExpressRunner runner = new ExpressRunner(); DefaultEnvironmentWorker.start(); IExpressContext<String,Object> expressContext = new DefaultContext<>(); DefaultService service = (DefaultService) ServiceProxy.temporary(ds); expressContext.put("service", service); DynamicParamsUtil.supportDynamicParams = true; Object r = runner.execute( "import org.anyline.service.init.DefaultService;\n" + "sorts = service.querys(\"sys_users\");\n" + "System.out.println(sorts);\n", expressContext, null,false, false); }

org.anyline anyline-environment-spring-data-jdbc 8.7.2-20240825
    <dependency>
        <groupId>org.anyline</groupId>
        <artifactId>anyline-data-jdbc-mysql</artifactId>
        <version>8.7.2-20240825</version>
    </dependency>
hvne4j commented 3 weeks ago

构造函数用不定参数好像也不行

public DefaultConfigStore(String ... configs) { configs = BasicUtil.compress(configs); chain = new DefaultConfigChain(); for(String config:configs) { chain.addConfig(parseConfig(config)); } }

image

hvne4j commented 3 weeks ago

是不是因为没覆盖到 default里的方法 default DataSet querys(String dest, String... conditions) { return this.querys((String)dest, (Object)null, conditions); }