[X] 中的 [getAssociatedToEntities] 操作接受类型为 [java.util.List] 的参数

The [getAssociatedToEntities] action in [X] accepts a parameter of type [java.util.List]

上下文

我在 Grails 2.4.4 中有一个使用 Spring Security Rest Plugin 1.5.4 for Grails along with Spring Security Core 2.0.0 的项目,我收到此 警告:

Warning |
The [getAssociatedToEntities] action in [security.UserController] accepts a parameter of type [java.util.List].  Interface types and abstract class types are not supported as command objects.  This parameter will be ignored.

       @Secured("hasAnyRole('READ__USER', 'READ__PROFILE')")
       ^

这是代码...

构建配置

//...
compile "org.grails.plugins:spring-security-core:2.0.0"
compile "org.grails.plugins:spring-security-rest:1.5.4"
//...

UserController(警告来自的代码!)

@Secured("hasAnyRole('READ__USER', 'READ__PROFILE')")
def getAssociatedToEntities(List<Long> e, SearchCommand cmd){
    //code omitted
}

问题:

我怎样才能去掉那个警告?

提前致谢!

将其包装在列表中:@Secured("hasAnyRole(['READ__USER', 'READ__PROFILE'])")

java.util.List is an Interface which cannot be used as a Command Object,试试这个:

创建一个包含列表的命令对象

import grails.validation.Validateable

@Validateable
class SearchListCommand extends SearchCommand {
  List values
}

并在 getAssociatedToEntities 操作中用命令对象替换列表的声明

def getAssociatedToEntities(SearchListCommand listCommand) { 
     //code omitted...
}