springboot-controller的使用

获取url中的数据:

@RestController
public class HelloController {
    
    @RequestMapping(value="/say/{id}", method = RequestMethod.GET)
    public String say(@PathVariable("id") Integer id){
        
        return "id:"+id;
    }
}

在输入url地址:http://127.0.0.1:8081/girl/say/23

显示:id:23

 

用传统的方式http://127.0.0.1:8081/girl/say?id=11

获取到其中的参数:

@RestController
public class HelloController {
    
    @RequestMapping(value="/say", method = RequestMethod.GET)
//@GetMapping(value="/say") 简化的写法
public String say(@RequestParam("id") Integer myid){ return "id:"+myid; } }

 

posted @ 2018-02-28 17:56  开拖拉机的蜡笔小新  阅读(357)  评论(0编辑  收藏  举报