我想从这个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 with
required=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";
}