gpt4 book ai didi

java - 为什么在 Controller 方法上调用时 getParameterTypes 为空?

转载 作者:行者123 更新时间:2023-12-01 23:03:35 25 4
gpt4 key购买 nike

如果我有一个 Controller 方法的实例,是通过在 Controller 的 Class 对象上调用 getMethod 获得的,为什么该方法(定义为采用 1 个参数)的“getParameterTypes”为空数组?

有没有办法真正获取它接受的参数类型?

最佳答案

如果您定义一个接受任何参数的 Controller 操作,Grails 编译器会生成相应的无参数方法。

class MyController {
// you write an action like this...
def someAction(String name, Integer age) {
// your code here
}

// the Grails compiler generates this additional method...
def someAction() {
// do some stuff needed by the framework

// ...

// initialize parameters

def name = ...
def age = ...

// call the original method
someAction(name, age)
}
}

我希望您在 Grails 编译器生成的方法上调用 getParameterTypes,而不是原始方法。

关于java - 为什么在 Controller 方法上调用时 getParameterTypes 为空?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23162372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com