grails服务回调的约束-属性需要首字母大写 [英] grails constraint for service callback - property needs capital first letter

查看:76
本文介绍了grails服务回调的约束-属性需要首字母大写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经升级了grails项目1.3.9-> 2.2,现在我遇到了有关回调到具有大写首字母的外部服务的约束的错误.我已经删除了此属性的约束要求,但想找到一种方法来保留约束功能,但我需要拥有一个带有大写字母的属性.我不控制发送回大写参数的外部API.

I've upgraded a grails project 1.3.9 -> 2.2 and now i get an error regarding the constraints of a callback to an external service having a capitalised first letter. I've removed the constraint requirement for this property, but would like to find a way to keep the constraint functionality but i need to have a property with a capital letter. I do not control the external API that is sending a capitalised param back.

回调关闭看起来像这样:

The callback closure looks like this:

class CallbackCommand{                                                                                                                                                       
   String token                                                                                                                                                                    
   String ID                                                                                                                                                                  

   static constraints = {                                                                                                                                                          
      token nullable: false                                                                                                                                                        
      //ID nullable: false                                                                                                                                                    
   }                                                                                                                                                                               
} 

我评论了ID约束,因为由于大写的第一个字母而使ID约束失败. 我该如何实施此约束,但要使参数命名与外部API保持一致?

I've commented the ID constraint as this fails due to the capitalised first letter. How can i enforce this constraint but keep the parameter naming consistent with the external API?

推荐答案

ID属性定义自定义验证器,如下所示:

Define a customized validator for ID property like this:

@grails.validation.Validateable
CallbackCommand{                                                                                                                                                       
    String token                                                                                                                                                                    
    String ID                                                                                                                                                                  

    static constraints = {                                                                                                                                                          
        token nullable: false 

        ID(validator:{val,obj->
            return(obj.ID != null)
        })
    }
}

这篇关于grails服务回调的约束-属性需要首字母大写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆