1

Here is my controller:

@RestController
@RequestMapping("/warning/data")
public class EarlyWarningDataController {

    @RequestMapping(value = "/get/{soeid}/{gfcid}/{expressioncode}/{fiscalYear}/{timeperiod}", 
                method = RequestMethod.GET)
        public String getEarlyWarningData(@PathVariable("soeid") String soeId,
                @PathVariable("gfcid") String[] gfcId,
                @PathVariable("expressioncode") String expressionCode,
                @PathVariable("fiscalYear") Long fiscalYear,
                @PathVariable("timeperiod") String timePeriod) throws IOException {
        sysout("");
    }

When I hit url

htpt://xyz:8080/EarlyWarning/warning/data/get/samplesoeid/1005771621/CAT_TOTAL_REV/2012/Annual 

it works fine.

but I want to send url something like:

htpt://xyz:8080/EarlyWarning/warning/data/get/soeid=samplesoeid/gfcid=1005771621/expressioncode=CAT_TOTAL_REV/fiscalyear=2012/timeperiod=Annual

What are the changes in code do I need to do? pl help.

Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
Anil Gavate
  • 49
  • 2
  • 8

2 Answers2

1

You should maybe convert those parameters into @RequestParam, not @PathVariable. @RequestParams are essentialy query parameters (those after the ? in the URL, divided by the &, like http://www.example.com?field1=value1&field2=value2&field3=value3...).

You can find the documentation here : http://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html

Difference between a @PathVariable and @RequestParam is discussed here: @RequestParam vs @PathVariable

Community
  • 1
  • 1
Aleksandar Stojadinovic
  • 4,851
  • 1
  • 34
  • 56
  • I'm not really a Spring expert (I believe you are using Spring for building this), but you cannot use `@QueryParam`. It is from the JAX-RS framework, Spring utilizes `@RequestParam` which is the equivalent. – Aleksandar Stojadinovic Nov 11 '14 at 09:37
1

You should pass key value data as query parameters, in the case of your example something like:

http://xyz:8080/Earlywarnings/warning?soeid=samplesoeid&gfcid=1005771621&expressioncode=CAT_TOTAL_REV&fiscalyear=2012&timeperiod=Annual

don't specifiy the method in the url, its already known.

Look at this answer for more on getting the parameters:

Get Query String Values in Spring MVC Controller

Community
  • 1
  • 1
Kevin
  • 750
  • 2
  • 10
  • 20