如果我有一个 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/