在 Spring Roo 2.0 中,使用 JSON 更新 object 会创建一个新的
In Spring Roo 2.0, using JSON to update an object creates a new one instead
在 Spring Roo 2.0 中,使用 JSON 更新 object 会创建一个新的。
当我尝试使用 JSON 更新 object 时,我在数据库中得到了一个新的 object,而不是更新原来的 object。我做错了什么吗?
更改前的工单。设备引用字段为空,所以我想更改它。
{
"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
}
要更改 object,我正在使用:
方法=PUT,url=”http://localhost:8000/json/tickets/26”
Headers: Content-Type=application/json, 接受=application/json
Body:
{
"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 项目。
只需在 JSON 请求正文中包含 id
和 version
字段。如果缺少任何一项,JPA EntityManager 将创建一个新项(如您所见)。
祝你好运!
在 Spring Roo 2.0 中,使用 JSON 更新 object 会创建一个新的。
当我尝试使用 JSON 更新 object 时,我在数据库中得到了一个新的 object,而不是更新原来的 object。我做错了什么吗?
更改前的工单。设备引用字段为空,所以我想更改它。
{
"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
}
要更改 object,我正在使用: 方法=PUT,url=”http://localhost:8000/json/tickets/26” Headers: Content-Type=application/json, 接受=application/json Body:
{
"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 项目。
只需在 JSON 请求正文中包含 id
和 version
字段。如果缺少任何一项,JPA EntityManager 将创建一个新项(如您所见)。
祝你好运!