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

标签 java grails groovy

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

相关文章:

java - 在 Windows 资源管理器中显示 Eclipse 中的文件

java - 如果不会发生争用,读取时是否需要同步

java - 如何在 Textdrawable 库中添加前两个字符?

javascript - Grails、javascript 渲染模板后不响应

unix - Groovy 安装错误

java - 在win vista上安装Jboss应用服务器

grails - Grails编译但Groovy失败

spring - 通过CAS Spring Security获得重定向循环

gradle - 如何在build.gradle中定义和调用自定义方法?

grails - 获取类的所有 transient 字段