使用 Spring 从 http link 引导获取值
Get values with Spring Boot from http link
我想从这个 http link:
中获取值
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 link 并获取 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";
}
我想从这个 http link:
中获取值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 link 并获取 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";
}