【问题标题】:Grails currencyInstance.properties not set after currencyInstance.properties = paramsGrails currencyInstance.properties 在 currencyInstance.properties = params 之后未设置
【发布时间】:2013-12-07 19:00:35
【问题描述】:

我正在使用 Grails 2.3.3

在货币控制器中。之后

currencyInstance.properties = params

currencyInstance.properties 不会改变。

但是如果我设置 currencyInstance.properties 会改变

currencyInstance.code = params.code
currencyInstance.name = params.name

这是我的参数:

println "Here is params: $params"

==> Here is params: [id:34, name:Australian dollar 1, code:AUD, version:4]

和域

class Currency {

    String code;
    String name;

    static constraints = {
        code blank : false;
        code unique: true;
    }

    static mapping = {
    }

}

【问题讨论】:

  • 你是如何检查属性没有改变的?您是否保存了您的实例?
  • 我首先通过 IDEA 中的 Evaluate Expression 检查,然后通过保存实例检查。如果我设置 def parmas_map = new HashMap() parmas_map.put("name", "test 11111") currencyInstance.properties = parmas_map.它工作

标签: grails grails-controller


【解决方案1】:

我发现错误是我的失败
1 - 如果我将 http PUT 发送到 http://localhost:8080/test_parmas/api/currencies/9?name=zzzzzz 并设置 Header Content-Type = application/json 但将空的正文数据发送到服务器。

2 - 如果我将 HTTP PUT 发送到 http://localhost:8080/test_parmas/api/currencies/9 并设置 Header Content-Type = application/json 和 body-data (id = 9)

{
"id":9
"name":"Australian dollar 111"
}

如果
1 - 如果我将 http PUT 发送到 http://localhost:8080/test_parmas/api/currencies/9?name=zzzzzz

2 - 如果我将 HTTP PUT 发送到 http://localhost:8080/test_parmas/api/currencies/9 并设置 Header Content-Type = application/json 和 body-data

{
"name":"Australian dollar 111"
}

【讨论】:

    猜你喜欢
    • 2014-05-28
    • 2013-01-11
    • 2021-08-24
    • 1970-01-01
    • 1970-01-01
    • 2020-07-08
    • 2014-05-05
    • 1970-01-01
    • 2011-12-09
    相关资源
    最近更新 更多