[method]操作接受未使用@Validateable标记的[org ... JSONObject]类型的参数。

GSA*_*SAN 3 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 validateable.

   def addPeople(JSONObject jsonsito) {
Run Code Online (Sandbox Code Playgroud)

如果我将JSONObject更改为def,则警告消失。我确定引用是JSONObject。我这样做是为了避免将来出现PermGem错误。

任何人都可以解释如何用@Validateable标记此OBJ?

提前致谢。

Jef*_*own 5

任何人都可以解释如何用@Validateable标记此OBJ?

你不能 该JSONObject班是不是你的代码的一部分,所以你不要让它@Validateable

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

  1. 创建该参数是其实例的类的实例
  2. 对实例进行数据绑定
  3. 对实例进行依赖注入
  4. 如果实例为@Validateable,则调用.validate()
  5. 然后您的方法中的代码最终被执行

步骤4是有条件的,只有在对象为时才会发生@Validateable。在您的情况下就不会了,这很好。警告只是让您知道。

附带说明一下,如果参数类型是String8个基本类型之一或8个类型包装之一的域类,则上述过程将有所不同。我上面描述的是系统对所有其他类型的行为。