Created
January 15, 2015 06:39
-
-
Save adrianmilne/6c0102ae708095eda6dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.cor.controller; | |
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo; | |
import static org.springframework.hateoas.mvc.ControllerLinkBuilder.methodOn; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.hateoas.Resource; | |
import org.springframework.http.MediaType; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.web.bind.annotation.PathVariable; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.RequestMethod; | |
import org.springframework.web.bind.annotation.ResponseBody; | |
import com.cor.domain.Artist; | |
import com.cor.service.MusicService; | |
@Controller | |
public class ArtistController { | |
@Autowired | |
private MusicService musicService; | |
@RequestMapping(value = "/artist/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) | |
@ResponseBody | |
public Resource<Artist> getArtist(@PathVariable(value = "id") String id) { | |
Artist a = musicService.getArtist(id); | |
Resource<Artist> resource = new Resource<Artist>(a); | |
resource.add(linkTo(methodOn(ArtistController.class).getArtist(id)).withSelfRel()); | |
return resource; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment