Search code examples
javaspring-bootwebgetmethod

request mapping with special char for attributes similar to google maps


I am using Spring boot and I want to pass two double values in a manner similar to Google maps: instead of having /api?x=1.1&y=2.2 and get the request parameters I want to do: /api/@1.1,2.2

At the level of the controller, how can I get those two parameters from the second get request?


Solution

  • @GetMapping("/api/@{term:.+}")
    public void index(@PathVariable String term) {
        // term is whatever after the "@"
        // you can parse the term to what you want
        // {term:.+} is a regex mapping for including the last dot
    }
    

    e.g.
    If you request ../api/@1.1,2.2
    Term will be "1.1,2.2".
    Split the term by "," and convert the strings to doubles.