【问题标题】:Why spring create tow identical links for self and rel?为什么 spring 为 self 和 real 创建两个相同的链接?
【发布时间】:2018-04-15 19:56:23
【问题描述】:

我不明白为什么 spring 为 selfrel 创建相同的链接?有没有办法禁用它?我认为这只是我的问题,因为我在阅读的文档中没有遇到这样的问题。

这是我的实体映射:

@Getter
@Setter
@Document
public class Ad {
    @Id
    private String id;
    private String description;
    private Banner banner;
}

@Getter
@Setter
public class Banner {
    private String id;
    private String filename;
}

这是我的存储库:

@RepositoryRestResource
public interface AdRepository extends CrudRepository<Ad, String> {
}

我点击以下网址:http://localhost:8558/ads

我不使用任何预测。我的应用程序现在很原始。没有什么具体的。

提前致谢!

【问题讨论】:

  • 你能分享你的实体映射代码吗?
  • @szxnyc,当然。完成了
  • 您的请求是什么样的?你在使用投影吗?
  • @szxnyc,我在问题中回答,请查收

标签: spring spring-data-rest spring-hateoas


【解决方案1】:

我唯一的猜测是你可能缺少 hashCode/equals 并且这会导致问题

【讨论】:

  • 我刚查过,不是hashCode/equals引起的
【解决方案2】:

这是设计使然。基于rel 的链接允许您查看所有上下文,而self 链接用作规范链接

为了进一步澄清,调整您的存储库定义以扩展不是CrudRepository,而是PagingAndSortingRepository。由于扩展的模板选项,为每个聚合根呈现的两个链接会立即看起来略有不同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-10
    • 1970-01-01
    • 2020-02-23
    • 1970-01-01
    • 1970-01-01
    • 2021-03-31
    • 2019-04-23
    相关资源
    最近更新 更多