Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

不定参数问题 #349

Open
hvne4j opened this issue Aug 29, 2024 · 4 comments
Open

不定参数问题 #349

hvne4j opened this issue Aug 29, 2024 · 4 comments

Comments

@hvne4j
Copy link

hvne4j commented Aug 29, 2024

版本 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
Copy link
Collaborator

image

函数签名传递的不对

@hvne4j hvne4j closed this as completed Aug 29, 2024
@hvne4j hvne4j reopened this Aug 29, 2024
@hvne4j
Copy link
Author

hvne4j commented Aug 29, 2024

请教一下,为什么我运行这个就会找不到方法呢?
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
Copy link
Author

hvne4j commented Aug 29, 2024

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

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

image

@hvne4j
Copy link
Author

hvne4j commented Aug 30, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants