0

I am trying to implement hypermedia using the spring-hateoas plugin.

I don't have JPA hibernate like in this example : https://spring.io/blog/2015/09/15/react-js-and-spring-data-rest-part-2-hypermedia

But I do really like the result. The only thing is I don't wan't to use JPA, I'd rather use mybatis.

I looked at Greg Turniquist projects and documentation and I still don't understand how to implement it in my project.

I wan't to use pagination, but I don't have any CrudRepository.

  1. Is this project working only for JPA ?
  2. Is there any example of a mybatis spring-boot spring-hatoas implementation ?
  3. Does anyone have any information on how to implement it with mybatis ?
Dimitri Kopriwa
  • 13,139
  • 27
  • 98
  • 204

1 Answers1

0

The trick with hateoas with JPA is that it works out of the box. That does not mean that you cannot create API with same hateoas responses without JPA, though. You just have to create your own controllers and configure each response manually.

There are several ways how to do it. There is a nice introductory tutorial from Spring on this topic: https://spring.io/guides/gs/rest-hateoas/

If you want to return hateoas resources, you can try something like this:

@RequestMapping("/myEntity")
public Resource<MyEntity> getMyEntity(String title) {
        MyEntity entity = // load your entity here

        // Provide a link to lookup of this resource
        Link entityLink = linkTo(MyEntityController).slash('/myEntity').withSelfRel()
        return new Resource<MyEntity>(entity, entityLink.expand(entity.entityId))
}
Smajl
  • 7,555
  • 29
  • 108
  • 179