Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重复链接键在投影REST响应中_Java_Spring Boot_Spring Hateoas - Fatal编程技术网

Java 重复链接键在投影REST响应中

Java 重复链接键在投影REST响应中,java,spring-boot,spring-hateoas,Java,Spring Boot,Spring Hateoas,为了在投影的Json框架中添加链接,我添加了以下类: @Component public class ResumeEntityProjectionResourceProcessor implements ResourceProcessor<Resource<ResumeEntity>> { @Override public Resource<ResumeEntity> process(Resource<ResumeEntity> resource

为了在投影的Json框架中添加链接,我添加了以下类:

@Component
public class ResumeEntityProjectionResourceProcessor implements ResourceProcessor<Resource<ResumeEntity>> {

@Override
public Resource<ResumeEntity> process(Resource<ResumeEntity> resource) {

    UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath()
            .path("/api/entities/search/findEntities")
            .buildAndExpand(Long.toString(resource.getContent().getId()));
    resource.add(new Link(uriComponents.toUriString(), "findEntities"));

    return resource;
}
我是怎么做到只保留第一个标签的

预期结果

{
"_embedded": {
    "entities": [{
            "id": 1696,
            "reference": "aaaaaa",
            "_links": {
                "self": {
                    "href": "http://localhost:8080/myProject/api/entities/1696{?projection}",
                    "templated": true
                },
                "findByParametresValide": {
                    "href": "http://localhost:8080/myProject/api/entities/search/findEntities"
                }
            }
        }
    ]
}
}
谢谢

@Override
公共资源流程(资源){
如果(resource.getLinks().isEmpty()){
返回资源;
}
UriComponents UriComponents=ServletUriComponentsBuilder.fromCurrentContextPath()
.path(“/api/entities/search/findEntities”)
.buildAndExpand(Long.toString(resource.getContent().getId());
添加(新链接(uriComponents.toUriString(),“findEntities”);
返回资源;
}

尝试将链接添加到资源..为了解决此问题,我在下面的资源对象上添加了测试
@覆盖公共资源进程(资源资源){if(resource.getLinks().isEmpty()){return resource;}UriComponents UriComponents=ServletUriComponentsBuilder.fromCurrentContextPath().path()(“/api/entities/search/findentials”).buildAndExpand(Long.toString(resource.getContent().getId());resource.add(新链接(uriComponents.toUriString(),“findentials”);return resource;}
{
"_embedded": {
    "entities": [{
            "id": 1696,
            "reference": "aaaaaa",
            "_links": {
                "self": {
                    "href": "http://localhost:8080/myProject/api/entities/1696{?projection}",
                    "templated": true
                },
                "findByParametresValide": {
                    "href": "http://localhost:8080/myProject/api/entities/search/findEntities"
                }
            }
        }
    ]
}
}
@Override
public Resource<ResumeEntity> process(Resource<ResumeEntity> resource) {
if (resource.getLinks().isEmpty()) { 
return resource; 
}
    UriComponents uriComponents = ServletUriComponentsBuilder.fromCurrentContextPath()
            .path("/api/entities/search/findEntities")
            .buildAndExpand(Long.toString(resource.getContent().getId()));
    resource.add(new Link(uriComponents.toUriString(), "findEntities"));

    return resource;
}