title: Spring get link to an entity
body: <p>I'm using Spring-boot-starter-data-jpa, in my RestController I want to return the Location of newly created object. Is there a way to reverse the @RequestMapping's and not hardcode how to build the URL?</p>
  
  <pre><code>@RestController
  @ExposesResourceFor(BookInstance.class)
  public class BookInstanceController {
      @RequestMapping(value="/bookInstances", method=RequestMethod.POST)
      ResponseEntity&lt;BookInstance&gt; createBookInstance(@RequestBody BookInstance bookInstance){
      BookInstance createdBookInstance = bookInstanceRepository.save(bookInstance);
  
      return ResponseEntity.created(**reverseURL(createdBookInstance)**);
  //      return new ResponseEntity&lt;BookInstance&gt;(createdBookInstance, HttpStatus.CREATED);
  //      return createdBookInstance;
      }
  }
  </code></pre>
  
  <p>I always see people hard-coding their URL construction in this function, which just leaves me without words.... </p>
  
  <p>Of course I also have a GET function in the same class (otherwise there wouldn't be anything to reverse)</p>
  
  <pre><code>@RequestMapping(value="/bookInstances/{id}", method=RequestMethod.GET)
  ResponseEntity&lt;?&gt; findOne(@PathVariable("id") Long id){
          BookInstance bookInstance = bookInstanceRepository.findOne(id);
          if(bookInstance == null){
              return ResponseEntity.notFound().build();
          }
          return new ResponseEntity&lt;BookInstance&gt;(bookInstance, HttpStatus.OK);
      }
  </code></pre>