当前位置:   article > 正文

Spring Boot路由参数配置_springboot 主键,参数路由

springboot 主键,参数路由

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中接受参数,可以直接在方法里用了。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/516797
推荐阅读
相关标签
  

闽ICP备14008679号