Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.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 春夏佳节;HAL:更改_embedded中的数组名称_Java_Spring_Spring Hateoas - Fatal编程技术网

Java 春夏佳节;HAL:更改_embedded中的数组名称

Java 春夏佳节;HAL:更改_embedded中的数组名称,java,spring,spring-hateoas,Java,Spring,Spring Hateoas,我正试图用SpringHateOAS构建一个符合HAL的RESTAPI 经过一番努力后,我几乎像预期的那样开始了工作。 此时(示例)输出如下所示: { "_links": { "self": { "href": "http://localhost:8080/sybil/configuration/bricks" } }, "_embedded": { "brickDomainList": [

我正试图用SpringHateOAS构建一个符合HAL的RESTAPI

经过一番努力后,我几乎像预期的那样开始了工作。 此时(示例)输出如下所示:

{
    "_links": {
        "self": {
            "href": "http://localhost:8080/sybil/configuration/bricks"
        }
    },
    "_embedded": {
        "brickDomainList": [
            {
                "hostname": "localhost",
                "port": 4223,
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/sybil/configuration/bricks/localhost"
                    }
                }
            },
            {
                "hostname": "synerforge001",
                "port": 4223,
                "_links": {
                    "self": {
                        "href": "http://localhost:8080/sybil/configuration/bricks/synerforge001"
                    }
                }
            }
        ]
    }
}
我不喜欢“brickDomainList”数组的名称。理想情况下,应该说是“砖块”。我怎样才能改变它

以下是生成输出的控制器:

@RestController
@RequestMapping("/configuration/bricks")
public class ConfigurationBricksController {

    private BrickRepository brickRepository;
    private GraphDatabaseService graphDatabaseService;

    @Autowired
    public ConfigurationBricksController(BrickRepository brickRepository, GraphDatabaseService graphDatabaseService) {

        this.brickRepository = brickRepository;
        this.graphDatabaseService = graphDatabaseService;
    }

    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, produces = "application/hal+json")
    public Resources<BrickResource> bricks() {

        List<BrickDomain> bricks;
        List<BrickResource> resources = new ArrayList<>();
        List<Link> links = new ArrayList<>();

        Link self = linkTo(ConfigurationBricksController.class).withSelfRel();
        links.add(self);

        try(Transaction tx = graphDatabaseService.beginTx()) { // begin transaction

            // get all Bricks from database and cast them into a list so that they're actually fetched
            bricks = new ArrayList<>(IteratorUtil.asCollection(brickRepository.findAll()));

            // end transaction
            tx.success();
        }

        for (BrickDomain brick : bricks) {
            self = linkTo(methodOn(ConfigurationBricksController.class).brick(brick.getHostname())).withSelfRel();

            BrickResource resource = new BrickResource(brick, self);

            resources.add(resource);
        }

        return new Resources<>(resources, links);
    }
}
@RestController
@请求映射(“/configuration/bricks”)
公共类配置BricksController{
私人砖厂;
专用GraphDatabaseService GraphDatabaseService;
@自动连线
公共配置BrickController(BrickRepository BrickRepository,GraphDatabaseService GraphDatabaseService){
this.brickRepository=brickRepository;
this.graphDatabaseService=graphDatabaseService;
}
@应答器
@RequestMapping(method=RequestMethod.GET,products=“application/hal+json”)
公共资源({
列出砖块;
List resources=new ArrayList();
列表链接=新建ArrayList();
Link self=linkTo(ConfigurationBricksController.class).withSelfRel();
links.add(self);
try(Transaction tx=graphDatabaseService.beginTx()){//begin Transaction
//从数据库中获取所有砖块,并将它们放入列表中,以便实际获取它们
bricks=newarraylist(IteratorUtil.asCollection(brickRepository.findAll());
//结束交易
成功();
}
用于(砖块领域砖块:砖块){
self=linkTo(methodOn(ConfigurationBricksController.class).brick(brick.getHostname()).withSelfRel();
BrickResource资源=新的BrickResource(砖,自身);
资源。添加(资源);
}
返回新资源(资源、链接);
}
}
是否可以添加一些注释或内容来更改数组的名称

如果您想/需要查看BrickResource类或存储库或其他内容,请查看以下内容:

BrickResource位于api/resources/中,存储库位于database/中,BrickDomain/中

谢谢

就用吧。如果您有一个Maven项目,那么添加依赖项

<dependency>
  <groupId>org.atteo</groupId>
  <artifactId>evo-inflector</artifactId>
  <version>1.2</version>
</dependency>

太好了,非常感谢,我要找的是
@relationship
注释:)我会支持你的答案,但我的声誉还不够,对不起:(托伯德:投你一票。何塞p:你可能也想提到
RelProvider
提供程序接口。它允许外部化rels的计算,以防用
@Relation
注释域对象是不可能的或需要的。不。将依赖项放在my.pom中,@springboot应用程序甚至注入了EvoReflectorBean。)…什么也没发生。是否缺少一些注释???总是看到domainClassResource:[…]会感到非常沮丧
@Relation(collectionRelation = "bricks")
public class BrickDomain { … }