Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RequestMapping is not identifying ?(question mark) as part of parameter passed with java REST Call

Tags:

spring-mvc

Follow this :

@RequestMapping(value = {"/abcd/id={id}","/abcd?id={id}"}, method = RequestMethod.GET)

public ModelAndView test(@PathVariable("id") String id) {

I have specified two type of values above in my code. former works fine when we call the uri but later is not getting identified (i.e.) @RequestMapping is not identifying ?(question mark) as part of parameter passed.

like image 217
gjosh Avatar asked Sep 20 '25 01:09

gjosh


2 Answers

You should get params on URL using @RequestParam as a method parameter.

@RequestMapping(value = "/abcd", method = RequestMethod.GET)
public void test(@RequestParam String id) {
    // your code here
}
like image 163
jelies Avatar answered Sep 23 '25 10:09

jelies


Question mark in urls (and uris) is used to separate parameters from the path.

@RequestMapping takes a path as it's value attribute. Hence it shouldn't contain question marks.

So basically your first case is interpreted as a path (although a strange one) and the second one is simply wrong.

like image 21
soulcheck Avatar answered Sep 23 '25 11:09

soulcheck