簡體   English   中英

REST調用后使用HTTPBuilder和Grails出現奇怪的“新”屬性

[英]Strange “new” property appearing after REST call using HTTPBuilder and Grails

我有一個grails控制器使用HTTPBuilder對Spring后端進行REST調用:

def getSettings(String customerID) {
    def http = new HTTPBuilder( grailsApplication.config.com.company.product.productWebserviceURL )
    def result = [:]
    def postBody = [customerID: customerID]

    try {
        http.post(path: 'product/getSettings', body: postBody, requestContentType: URLENC) { resp, json ->
            result = json
        }
    } catch (IOException ex) {
        logger.error("Cannot in attempting to get settings via webservice for customerID: " + customerID + ". Is the server running? \nError: " + ex.getMessage())
        result['errors'] = [[message : this.CUSTOMER_FACING_TRANSACTIONHISTORY_DOWN_MESSAGE]]
        response.status = 500;
    }
    render result as JSON
}

一切都很好,除了獲得JSON響應之外,還有一個名為“new”的新屬性。 以下是我的Spring后端將作為JSON返回的Settings對象:

將要作為JSON返回的對象

這里它是grails控制器中的JSON響應。 注意不屬於原始Settings對象的額外第五個屬性:

得到答復后

有誰知道這個名為“新”的神秘財產如何不斷加入?

這里遇到spring-data jpa docs后

我看到,如果id列為null或非null,spring數據將添加一個屬性“new”。 以下內容直接來自文檔:

“Id-Property inspection(默認)默認情況下,Spring Data JPA檢查給定實體的Id-Property。如果Id-Property為null,則該實體將被假定為new,否則不是new。”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM