Grails [method]操作接受类型为[org…JSONObject]的参数,该参数未标记为@Validateable。

Grails [method]操作接受类型为[org…JSONObject]的参数,该参数未标记为@Validateable。,grails,groovy,warnings,Grails,Groovy,Warnings,我有一个警告: Warning |The [addPeople] action accepts a parameter of type [org.codehaus.groovy.grails.web.json.JSONObject] which has not been marked with @Validateable. Data binding will still be applied to this command object but the instance will not be

我有一个警告:

Warning |The [addPeople] action accepts a parameter of type [org.codehaus.groovy.grails.web.json.JSONObject] which has not been marked with @Validateable.  Data binding will still be applied to this command object but the instance will not be validateable.

   def addPeople(JSONObject jsonsito) {
如果我将JSONObject更改为def,警告将消失。我确信引用是一个JSONObject。我这样做是为了避免将来的错误

任何人都可以解释我如何用@validable标记这个OBJ

提前谢谢

任何人都可以解释我如何用@validable标记这个OBJ

你不能。
JSONObject
类不是代码的一部分,因此您无法将其设置为可验证的
@validatable

当控制器操作在编译时接受参数时,Grails会为您生成一组代码。总之,生成的代码执行以下操作:

  • 创建该参数作为其实例的类的实例
  • 对实例进行数据绑定
  • 对实例进行依赖项注入
  • 如果实例是可验证的,则调用
    .validate()
  • 然后,方法中的代码最终被执行
  • 步骤4是有条件的,仅当对象可验证时才会发生。在你的情况下不会,这很好。警告只是让你知道这一点


    作为旁注,如果参数类型是域类、
    String
    、8个基本类型之一或8个类型包装器之一,则上述过程不同。我上面描述的是系统在所有其他类型下的行为。

    我回答了问题,但作为旁注,我认为没有任何理由使用
    JSONObject
    作为控制器操作的参数。谢谢Jeff。理解。