0

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

@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 文件中进行任何更改,那么在自动编译验证之后就会开始工作。

这可能是什么原因?

我们将 grails-2.2.2 与 nginx 服务器一起使用。

4

0 回答 0