语境

我在 Grails 2.4.4 中有一个项目,使用 Spring Security Rest Plugin 1.5.4 for Grails连同 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 
} 

问题:我怎样才能摆脱这个警告?

提前致谢!

请您参考如下方法:

java.util.List 是一个不能用作 Command Object 的接口(interface),试试这个:

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

import grails.validation.Validateable 
 
@Validateable 
class SearchListCommand extends SearchCommand { 
  List values 
} 

并将列表的声明替换为 getAssociatedToEntities 中的命令对象行动
def getAssociatedToEntities(SearchListCommand listCommand) {  
     //code omitted... 
} 


评论关闭
IT序号网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!