Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adrianmilne/6c0102ae708095eda6dc to your computer and use it in GitHub Desktop.
Save adrianmilne/6c0102ae708095eda6dc to your computer and use it in GitHub Desktop.
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