grails命令对象验证不一致

时间:2016-02-25 14:59:52

标签: grails grails-2.2 grails-validation

我有以下带有约束的命令对象:

@Validateable
class RefundCommand{
    private static final Logger log = Logger.getLogger(RefundCommand.class)

    Double amount
    String order_id
    MerchantAccount merchant
    OrderReference order
    String unique_request_id

    public void getDerivedValues() {
        this.order = OrderReference.findByOrderIdAndMerchantId(order_id, merchant.merchantId)
    }

    static constraints = {
        amount nullable: false, validator: {amount, cmd->
          if(cmd.amount <= 0) {
                log.info("Amount must be greater than 0. Given value: ${cmd.amount}")
                return ['invalid.amount']
            }
        }
    }
}

在控制器内以下列方式启动对象:

def refund = {RefundCommand cmd->

    def String orderId = params.orderId
    def String merchantId = params.merchant.merchantId
    def Double amount = params.amount.toDouble()
    OrderReference orderReference = OrderReference.findByOrderIdAndMerchantId(orderId, merchantId)
    MerchantAccount merchantAccount = MerchantAccount.findByMerchantId(merchantId)
    cmd.order_id = orderId
    cmd.merchant = merchantAccount
    cmd.order = orderReference
    cmd.amount = amount
    cmd.unique_request_id = "rf_" + util.generateUniqueReference()
    cmd.clearErrors()
    cmd.validate()
    log.info(cmd.dump())
    if(cmd.hasErrors()) {
         ..... 
         return
    }
    proceedForRefund()
}

当我部署初始验证不起作用时,validate()始终返回true并且hasError()返回null。

由于我们正在使用nginx,如果我在RefundCommand文件中进行任何更改,那么在自动编译验证开始工作之后。

可能是什么原因?

我们正在使用带有nginx服务器的grails-2.2.2。

0 个答案:

没有答案