如何在JAX-RS/JEE中进行分页和Hateoas?

Adr*_*ebs 5 pagination jax-rs hateoas jakarta-ee

在 Spring 中将分页和 HATEOAS 添加到 REST 资源非常简单,并且开箱即用:

@RequestMapping(value = "/pages", method = RequestMethod.GET)
PagedResources<NoteResource> allPaged(@PageableDefault Pageable p, PagedResourcesAssembler<Note> pagedAssembler) {
    Page<Note> pageResult = noteRepository.findAll(p);
    return pagedAssembler.toResource(pageResult, noteResourceAssembler);
}
Run Code Online (Sandbox Code Playgroud)

就是这样。我可以调用localhost:8080/notes/pages?page=0&size=2并获取以下 JSON:

{
"_embedded": {
    "noteList": [
        {
            "id": 1,
            "title": "firstNote",
            "body": "lala",
            "_links": {
                "self": {
                    "href": "http://localhost:8080/notes/1"
                },
                "note-tags": {
                    "href": "http://localhost:8080/notes/1/tags"
                }
            }
        },
        {
            "id": 2,
            "title": "secondNote",
            "body": "blabla",
            "_links": {
                "self": {
                    "href": "http://localhost:8080/notes/2"
                },
                "note-tags": {
                    "href": "http://localhost:8080/notes/2/tags"
                }
            }
        }
    ]
},
"_links": {
    "first": {
        "href": "http://localhost:8080/notes/pages?page=0&size=2"
    },
    "self": {
        "href": "http://localhost:8080/notes/pages?page=0&size=2"
    },
    "next": {
        "href": "http://localhost:8080/notes/pages?page=1&size=2"
    },
    "last": {
        "href": "http://localhost:8080/notes/pages?page=5&size=2"
    }
},
"page": {
    "size": 2,
    "totalElements": 12,
    "totalPages": 6,
    "number": 0
}
Run Code Online (Sandbox Code Playgroud)

}

如何使用普通 JavaEE 和 JAX-RS 实现相同的目标?