简体   繁体   中英

How to implement spring-hateoas on a spring boot app that use mybatis instead of jpa

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 ?

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))
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM