Returned json unexpected, has “links” spelled as “_links” and structure different, in Spring hateoas

前端 未结 6 1778
情书的邮戳
情书的邮戳 2021-01-02 02:56

As the title says, I have a resource object Product extending ResourceSupport. However, the responses I receive have the property \"_links\" instea

6条回答
  •  难免孤独
    2021-01-02 03:22

    I am sure you are using Spring data with @RepositoryRestResource annotation

    @RepositoryRestResource    
    public interface XX extends CrudRepository
    

    If you want to remove default HAL behavior you can add following annotaion param

    @RepositoryRestResource(exported = false)
    public interface XX extends CrudRepository
    

    Above configurition Spring Data REST to only expose rest endpoints for resources in the parent project, without having to explicitly annotate every repository in the dependency project.

    As per doc

    Hiding certain repositories, query methods, or fields You may not want a certain repository, a query method on a repository, or a field of your entity to be exported at all. Examples include hiding fields like password on a User object or similar sensitive data. To tell the exporter to not export these items, annotate them with @RestResource and set exported = false.

    For example, to skip exporting a Repository:

    @RepositoryRestResource(exported = false)
    interface PersonRepository extends CrudRepository {}
    

提交回复
热议问题