【问题标题】:How to remove the "links_" property in Spring如何在 Spring 中删除“links_”属性
【发布时间】:2019-06-02 04:00:09
【问题描述】:

我正在使用 Spring Boot 构建 Web 服务。当我的 api 返回对象集合时,会添加“_links”属性。没有它们,有没有办法退货?

我的回答:

{"links":[],"content":[{"id":2,"bssid":["Eduo","Konfere"],"rssi":[55.04,63.03],"x":55.04,"y":66.05,"links":[]},{"id":3,"bssid":["TPLINK","MANTOR"],"rssi":[25.23,95.02],"x":51.01,"y":52.03,"links":[]}]}

我在寻找什么:

{"content":[{"id":2,"bssid":["Eduo","Konfere"],"rssi":[55.04,63.03],"x":55.04,"y":66.05},{"id":3,"bssid":["TPLINK","MANTOR"],"rssi":[25.23,95.02],"x":51.01,"y":52.03}]}

我的控制器的代码:

@GetMapping(value="/points", produces = "application/json; charset=UTF-8")
Resources<Resource<Points>> all() {

    List<Resource<Points>> points = repository.findAll().stream()
            .map(point -> new Resource<>(point)).collect(Collectors.toList());

    return new Resources<>(points);
}

将不胜感激任何帮助:)

【问题讨论】:

    标签: java spring hyperlink format response


    【解决方案1】:

    _links 属性很可能是由Spring HATEOAS 添加的。如果您不想使用它,只需将其从项目依赖项中排除即可。

    【讨论】:

    • 问题是如果我排除“org.springframework.bootspring-boot-starter-hateoas”我的 maven pom.xml,HATEOAS 的其他部分,如 Resources 将无法正常工作。
    • + 我的 application.properties 上有 spring.hateoas.use-hal-as-default-json-media-type=false
    猜你喜欢
    • 1970-01-01
    • 2015-05-02
    • 2013-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-11
    • 2021-02-20
    • 2017-06-24
    相关资源
    最近更新 更多