1. 程式人生 > >springboot結合idea開發工具學習一:springboot中的controller控制類

springboot結合idea開發工具學習一:springboot中的controller控制類

springboot結合idea開發工具學習二:springboot中的controller控制類

1.url路徑

在控制類前加代表訪問這個類下的所有方法都要加hello

@RequestMapping("/hello")

在方法前加這個代表 hello 和hi都可以訪問

 @RequestMapping(value = {"/hello","/hi"},method = RequestMethod.GET)

2.獲取url路徑引數

如下獲取  123

 /*設定傳參http://127.0.0.1:8081/pro/123*/
    @RequestMapping(value = "/pro/{id}",method = RequestMethod.GET)
    public  String pro(@PathVariable("id") Integer id){
        return "id:"+id;
    }

第二種  有?的

required  是否必須傳  defaultvalue 預設值是什麼

/*設定傳參http://127.0.0.1:8081/pro2?id=123 */
//    @RequestMapping(value = "/pro2",method = RequestMethod.GET)//和下面的一樣效果
    @GetMapping(value = "/pro2")
    public  String pro2(@RequestParam(value = "id",required = false,defaultValue = "0") Integer id){
        return "id:"+id;
    }