Add request method constraints to some request mappings

Some request mappings that were only intended to handle GET requests
were unconstrained. The commit adds a method = GET constraint to those
mappings to prevent them from handling other HTTP request methods
This commit is contained in:
Andy Wilkinson
2014-10-29 10:04:25 +00:00
parent 3ac27976ea
commit 34dcef2201
3 changed files with 5 additions and 4 deletions

View File

@@ -20,13 +20,14 @@ import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
import org.springframework.hateoas.ResourceSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/")
public class IndexController {
@RequestMapping
@RequestMapping(method=RequestMethod.GET)
public ResourceSupport index() {
ResourceSupport index = new ResourceSupport();
index.add(linkTo(NotesController.class).withRel("notes"));

View File

@@ -55,7 +55,7 @@ public class NotesController {
this.noteResourceAssembler = noteResourceAssembler;
}
@RequestMapping
@RequestMapping(method = RequestMethod.GET)
Iterable<NoteResource> all() {
return this.noteResourceAssembler.toResources(this.noteRepository.findAll());
}

View File

@@ -46,7 +46,7 @@ public class TagsController {
this.resourceAssembler = resourceAssembler;
}
@RequestMapping
@RequestMapping(method = RequestMethod.GET)
Iterable<TagResource> all() {
return this.resourceAssembler.toResources(this.repository.findAll());
}
@@ -65,7 +65,7 @@ public class TagsController {
return httpHeaders;
}
@RequestMapping("/{id}")
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
Resource<Tag> tag(@PathVariable("id") long id) {
Tag tag = this.repository.findOne(id);
return this.resourceAssembler.toResource(tag);