spring引导对象未完全转移到浏览器

3htmauhk  于 2021-07-24  发布在  Java
关注(0)|答案(0)|浏览(205)

我将一个对象从spring引导服务器传输到浏览器。

public class Document
{
    @Id
    private long documentId;
    private String documentNumber;
    private int index;
    private String checkSum;
    private OffsetDateTime createdAt;
    private User createdBy;
    private OffsetDateTime modifiedAt;
    private User modifiedBy;
    private String placeholder;
    private boolean indexing;
    private String changeLog;
    ... // Getter and Setter
}

但如果我在几分钟后将同一个对象发送到浏览器,则会丢失一些字段。如果我将同一请求发送两次到服务器,则缺少变量占位符、changelog和索引。

@PermitAll
@GetMapping("/test.do")
public ResponseEntity<Object> test()
{
    Document document = new Document();
    document.setDocumentId(1);
    document.setDocumentNumber("Test");
    document.setIndex(2);
    // ...
    document.setPlaceholder("Hello");
    document.setIndexing(true);
    document.setChangeLog("This is the first test");
    return new ResponseEntity<>(document, HttpStatus.OK);
}

我和 Postman 一起测试这个请求。

http://localhost/test.do
Response:
{
    "documentId": 1,
    "documentNumber": "Test",
    "index": 2,
    "checkSum": null,
    "createdAt": null,
    "createdBy": null,
    "modifiedAt": null,
    "modifiedBy": null,
    "placeholder": "Hello",
    "indexing": true,
    "changeLog": "This is the first test"
}

第二次通话后:

http://localhost/test.do
Response:
{
    "documentId": 1,
    "documentNumber": "Test",
    "index": 2,
    "checkSum": null,
    "createdAt": null,
    "createdBy": null,
    "modifiedAt": null,
    "modifiedBy": null
}

有人知道我在这个案子里做错了什么吗。我已经将spring引导框架版本升级到2.4.2。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题