在Spring Roo 2.0中,使用JSON更新对象会创建一个新对象

时间:2017-06-15 03:57:03

标签: json spring spring-roo

在Spring Roo 2.0中,使用JSON更新对象会改为创建一个新对象。

当我尝试使用JSON更新对象时,我在数据库中获得了一个新对象,而不是更新原始对象。我做错了吗?

进行更改前的票证。设备参考字段为空,因此我想更改它。

{
    "id": 26,
    "version": 0,
    "ticketNumber": "Ticket 1",
    "ticketName": "T1 name",
    "location": "somewhere",
    "description": "desc",
    "customerName": null,
    "projectNumber": "Project 1",
    "opportunity": null,
    "marketSegment": null,
    "createdBy": "me",
    "plannedCreateDate": 1496556000000,
    "createDate": 1496556000000,
    "ticketStatus": "SUBMITTED",
    "ticketObjective": null,
    "equipment": null,
    "ticketResult": null,
    "ticketConclusion": null,
    "pivotuser": null
}

要更改对象,我正在使用: Method = PUT,url =“http://localhost:8000/json/tickets/26” 标题:Content-Type = application / json,Accept = application / json 体:

{
    "ticketNumber": "Ticket 1",
    "ticketName": "T1 name",
    "location": "somewhere",
    "description": "desc"
    "customerName": null,
    "projectNumber": "Project 1",
    "opportunity": null,
    "marketSegment": null,
    "createdBy": "me"
    "plannedCreateDate": 1496556000000,
    "createDate": 1496556000000,
    "ticketStatus": "SUBMITTED",
    "ticketObjective": null,
    "equipment": 3,
    "ticketResult": null
    "ticketConclusion": null,
    "pivotuser": null
}

回复:200

再次获得门票:

"content": [
    {
        "id": 26,
        "version": 0,
        "ticketNumber": "Ticket 1",
        "ticketName": "T1 name",
        "location": "somewhere",
        "description": "desc",
        "customerName": null,
        "projectNumber": "Project 1",
        "opportunity": null,
        "marketSegment": null,
        "createdBy": "me",
        "plannedCreateDate": 1496556000000,
        "createDate": 1496556000000,
        "ticketStatus": "SUBMITTED",
        "ticketObjective": null,
        "equipment": null,
        "ticketResult": null,
        "ticketConclusion": null,
        "pivotuser": null
    },
    {
        "id": 27,
        "version": 0,
        "ticketNumber": "Ticket 1",
        "ticketName": "T1 name",
        "location": "somewhere",
        "description": "desc",
        "customerName": null,
        "projectNumber": "Project 1",
        "opportunity": null,
        "marketSegment": null,
        "createdBy": "me",
        "plannedCreateDate": 1496556000000,
        "createDate": 1496556000000,
        "ticketStatus": "SUBMITTED",
        "ticketObjective": null,
        "equipment": {
            "id": 4,
            "version": 0,
            "manufacturer": "manufacturer 1",
            "masterNumber": "master number 1",
            "ticket": {
                "id": 27,
                "version": 0,
                "ticketNumber": "Ticket 1",
                "ticketName": "T1 name",
                "location": "somewhere",
                "description": "desc",
                "customerName": null,
                "projectNumber": "Project 1",
                "opportunity": null,
                "marketSegment": null,
                "createdBy": "me",
                "plannedCreateDate": 1496556000000,
                "createDate": 1496556000000,
                "ticketStatus": "SUBMITTED",
                "ticketObjective": null,
                "equipment": 4,
                "ticketResult": null,
                "ticketConclusion": null,
                "pivotuser": null
            }
        },
        "ticketResult": null,
        "ticketConclusion": null,
        "pivotuser": null
    }

机票26没有改变。机票27是使用设备参考= 4创建的。 我究竟做错了什么。这是我的第一个JSON项目。

1 个答案:

答案 0 :(得分:0)

只需在JSON请求正文中包含idversion字段即可。如果缺少任何 JPA EntityManager 将创建一个新项目(如您所见)。

祝你好运!