Questions tagged [request-mapping]

Issues regarding usage of Spring MVC @RequestMapping methods

348 questions
156
votes
11 answers

Spring 3 RequestMapping: Get path value

Is there a way to get the complete path value after the requestMapping @PathVariable values have been parsed? That is: /{id}/{restOfTheUrl} should be able to parse /1/dir1/dir2/file.html into id=1 and restOfTheUrl=/dir1/dir2/file.html Any ideas…
Spring Monkey
  • 4,988
  • 7
  • 32
  • 34
128
votes
4 answers

Spring 3 MVC accessing HttpRequest from controller

I would like to handle request and session attributes myself rather then leave it to spring @SessionAttributes, for login of cookies handling for example. I just cant figure out how could I access the HttpRequest from within a controller, I need a…
JBoy
  • 5,398
  • 13
  • 61
  • 101
79
votes
3 answers

Combine GET and POST request methods in Spring

I have a resource that supports both GET and POST requests. Here a sample code for a sample resource: @RequestMapping(value = "/books", method = RequestMethod.GET) public ModelAndView listBooks(@ModelAttribute("booksFilter") BooksFilter filter, two…
user1120144
44
votes
5 answers

Spring mvc Ambiguous mapping found. Cannot map controller bean method

I am trying to build an app which can list some values from the database and modify, add, delete if necessary using Spring 4 and i receive the following error(only if the "@Controller" annotation is present in both of my controller files, if i…
Serban Gorcea
  • 549
  • 1
  • 4
  • 11
32
votes
4 answers

Understanding How Spring MVC's @RequestMapping POST Works

I have a simple Controller that looks like this:- @Controller @RequestMapping(value = "/groups") public class GroupsController { // mapping #1 @RequestMapping(method = RequestMethod.GET) public String main(@ModelAttribute GroupForm…
limc
  • 39,366
  • 20
  • 100
  • 145
30
votes
4 answers

Proper way of streaming using ResponseEntity and making sure the InputStream gets closed

One of our application leaks file handles and we have not yet found the cause for this. In the code I can see several functions similar to this: public ResponseEntity getFoo( ... ) { InputStream content = getContent(...) …
Marged
  • 10,577
  • 10
  • 57
  • 99
28
votes
1 answer

Custom Spring annotation for request parameters

I would like to write custom annotations, that would modify Spring request or path parameters according to annotations. For example instead of this code: @RequestMapping(method = RequestMethod.GET) public String test(@RequestParam("title") String…
arminas
  • 381
  • 1
  • 5
  • 13
25
votes
2 answers

Handling ambiguous handler methods mapped in REST application with Spring

I tried to use some code as below: @RequestMapping(value = "/{id}", method = RequestMethod.GET) public Brand getBrand(@PathVariable Integer id) { return brandService.getOne(id); } @RequestMapping(value = "/{name}", method =…
mikezang
  • 2,291
  • 7
  • 32
  • 56
23
votes
2 answers

Spring MVC referencing params variable from RequestMapping

I have the method below: @RequestMapping(value = "/path/to/{iconId}", params="size={iconSize}", method = RequestMethod.GET) public void webletIconData(@PathVariable String iconId, @PathVariable String iconSize, HttpServletResponse response) throws…
NomNomNom
  • 231
  • 1
  • 2
  • 4
22
votes
3 answers

Spring MVC: RequestMapping both class and method

Is this possible? @Controller @RequestMapping("/login") public class LoginController { @RequestMapping("/") public String loginRoot() { return "login"; } @RequestMapping(value="/error", method=RequestMethod.GET) public…
Orvyl
  • 2,635
  • 6
  • 31
  • 47
20
votes
7 answers

Sub-Resources in spring REST

I'm trying to build messanger app. I've to call CommentResource from MessageResource. I want separate MessageResources and CommentResources. I'm doing something like this : MessageResource.java @RestController @RequestMapping("/messages") public…
prranay
  • 1,789
  • 5
  • 23
  • 33
15
votes
1 answer

@RequestMapping annotation not allowed on @FeignClient interfaces

I'm having trouble with this! As I've been reading, it happens because it's no longer accepted. But how can I solved it? This is the code I've been trying to map. @FeignClient(name = "product-service") @RequestMapping("api/products/") public…
DiegoMG
  • 383
  • 1
  • 4
  • 18
12
votes
1 answer

Meaning of "params" in @RequestMapping annotation?

I am aware of @RequestMapping annotation which is used in Spring MVC based application. I came across this piece of code: @RequestMapping(method = POST, params = {"someParam"}) I understood the method. However I don't know what params means? Before…
CuriousMind
  • 8,301
  • 22
  • 65
  • 134
10
votes
2 answers

Where exactly is a model object created in Spring MVC?

After going through some tutorials and initial document reading from the docs.spring.org reference I understood that it is created in the controller of a POJO class created by the developer. But while reading this I came across the paragraph…
JAVA
  • 524
  • 11
  • 23
10
votes
1 answer

How @RequestMapping internally works in Spring Boot?

@RestController @RequestMapping("/employee") public class Employee { @RequestMapping("/save") public void saveEmployee() { // saving employee } } How does @RequestMapping will work internally to map the request to the saveEmployee method?
1
2 3
23 24