spring hateoas and spring doclet

5
Spring Hateoas This project provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and especially Spring MVC. The core problem it tries to address is link creation and representation assembly. 1. Set up Add maven dependency < dependency> <groupId>org.springframework.hateoas</groupId> <artifactId>spring-hateoas </artifactId> <version>0.7.0.RELEASE</version> <!—-newest version--> </ dependency> 2. To use String Hateoas, your original model view has to extend org.springframework.hateoas.ResourceSupport class. As pretty much every representation of a resource will contain some links (at least the self one) we provide a base class to actually inherit from when designing representation classes.

Upload: mot-ty-nguoi

Post on 28-Oct-2015

22 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Spring Hateoas and Spring Doclet

Spring HateoasThis project provides some APIs to ease creating REST representations that follow the HATEOAS principle when working with Spring and especially Spring MVC. The core problem it tries to address is link creation and representation assembly.

1. Set upAdd maven dependency

<dependency> <groupId>org.springframework.hateoas</groupId> <artifactId>spring-hateoas</artifactId> <version>0.7.0.RELEASE</version> <!—-newest version-->

</dependency>

2. To use String Hateoas, your original model view has to extend org.springframework.hateoas.ResourceSupport class. As pretty much every representation of a resource will contain some links (at least the self one) we provide a base class to actually inherit from when designing representation classes.

Page 2: Spring Hateoas and Spring Doclet

3. In your Controller class, after adding a device, you should return self-link to the added device for user can use this link to delete Device or get device information with this link. To add some links, you have to insert some codes below:

You can add any number of links you want, simply call add(Link link) on your object.4. After adding Device, you have JSON object contains link to the new added device.

Building links pointing to methods

1. An alternation for step 3, replace with below code to provide link to this new added device by building links pointing to methods.

Or

2. The same result as follow:

Page 3: Spring Hateoas and Spring Doclet

Spring docletSpringDoclet is a Javadoc doclet that generates documentation on Spring Framwork artifacts in a project. The detection of Spring artifacts is based on the presence of Spring annotations on Java classes and methods.

SpringDoclet currently detects and documents the following types of Spring artifacts:

Components - classes annotated with @Component, @Controller, @Repository, and @Service

RequestMappings - classes and methods annotated with @RequestMapping1. Set up

add this plugin to pom.xml file as a child of <plugins> element

Page 4: Spring Hateoas and Spring Doclet

2. Add this element as a child of <project> element

3. Open project’s root directory and type mvn site4. After building successfully, open target\site\index.html -> Project Reports -> Spring

Docs, you have result as below:

Page 5: Spring Hateoas and Spring Doclet