使用Spring Boot从http链接获取值



我想从这个http链接获取值:

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

我尝试实现这个Spring代码:

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

但是,我如何解析http链接并获得值,例如在HashMap的ArrayList中?

您的控制器方法应该是这样的,RequestParam要从请求中获取值,您可以使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";
}

相关内容

  • 没有找到相关文章

最新更新