加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

java – Spring HATEOAS&HAL:在_embedded中更改数组名称

发布时间:2020-12-15 01:32:08 所属栏目:大数据 来源:网络整理
导读:我正在尝试使用Spring HATEOAS构建符合HAL的REST API. 在一些摆弄之后,我设法开始工作,大多是预期的. (样本)输出现在看起来像这样: { "_links": { "self": { "href": "http://localhost:8080/sybil/configuration/bricks" } },"_embedded": { "brickDomainL

我正在尝试使用Spring HATEOAS构建符合HAL的REST API.

在一些摆弄之后,我设法开始工作,大多是预期的.
(样本)输出现在看起来像这样:

{
    "_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","_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类或Repositories或其他内容,请查看此处:https://github.com/ttheuer/sybil/tree/mvctest/src/main/java/org/synyx/sybil

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

谢谢!

最佳答案
只需使用Evo Inflector.如果您有Maven项目,则添加依赖项


或者,您可以将@Relation(collectionRelation =“bricks”)添加到BrickDomain类

@Relation(collectionRelation = "bricks")
public class BrickDomain { … }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读