Spring Boot路由参数配置

Spring Boot

  • package com.tang.demo1.controller;
  • import org.springframework.web.bind.annotation.*;
  • @RestController
  • public class RouterController {
@RequestMapping(path = {"/getJson/{name}/{id}"})
@ResponseBody
public Map<String,String> getJson(@PathVariable("name") String name,@PathVariable("id") Integer id,@RequestParam(value = "type",defaultValue = "news")String type,@RequestParam(value = "num",required = false) int num){
    Map<String,String> rMap = new HashMap<String, String>();
    rMap.put("name", "this is article's name : "+name );     // 5
    rMap.put("id", "this is article's id : " + id);
    rMap.put("type","this is article's type :"+type);
    rMap.put("num","this is article's num :"+num);
    return rMap;
}
}

在url路径中的参数,被称为pathVariable,查询参数被称为pequestParm。在controller中接受参数,可以直接在方法里用了。

猜你喜欢

转载自blog.csdn.net/jiaowo_ccc/article/details/79500047