Peter Penzov
Peter Penzov

Reputation: 1680

Get values with Spring Boot from http link

I want to get the values from this http link:

https://www.test.com/notification?con=41280440000097&dp=1232&type=single

https://www.test.com/notification?con=41280440000097&sec=1232

I tried to implement this Spring code:

    @PostMapping(value = "/v1/notification")
    public String handleNotifications(@RequestParam("notification") String itemid) {
        // parse here the values
    return "result";
    }

But how I can parse the http link and get the values for example in ArrayList of HashMap?

Upvotes: 2

Views: 511

Answers (1)

Ryuzaki L
Ryuzaki L

Reputation: 40078

your controller method should be like this with RequestParam to get the values from request, you can make RequestParam optional withrequired=falseand you can set default value also(@RequestParam(value = "i", defaultValue = "10") int i`

 @PostMapping(value = "/v1/notification")
public String handleNotifications(@RequestParam(value="con", required=false) String itemid, @RequestParam(value="dp", required=false) String dp, @RequestParam(value="type", required=false) String type ) 
    {
     // you can use all these values directly in this method
    // parse here the values
return "result";
}

Upvotes: 2

Related Questions