@RequestMapping接口动态参数

1.多参数Map接收

@RequestMapping(value = "/{version}/{cate}/{article}",method = RequestMethod.GET)
public String dynApiDemo(@PathVariable Map map){
    String version = map.get("version");
    String cateUrl = map.get("cate");
    String articleUrl = map.get("article");
    return version+"/"+cateUrl+"/"+articleUrl;
}

2.单参数接收

@RequestMapping(value = "/v1/{cate}",method = RequestMethod.GET)
public String dynApiDemo2(@PathVariable("cate")String cate){
    String cateUrl = map.get("cate");
    return "v1/"+cateUrl;
}

3.正则接收

@RequestMapping(value = "/regexp/{name:\\w}",method = RequestMethod.GET)
public String dynApiDemo3(@PathVariable("name")String name){
    System.out.println(name);
    return "";
}

4.占位符(一般不用,太捞了)

@RequestMapping(value = "/v1/**",method = RequestMethod.GET)
public String dynApiDemo4(){
    return "";
}

你可能感兴趣的:(java)