zoukankan      html  css  js  c++  java
  • 2小时学会Spring Boot学习-controller的使用

    新建HelloController类
    添加注解

    @RestController  //等同于@Controller+@ResponseBody
    @RequestMapping(value = "hello")  //访问此controller类时, hello为'父'路径 localhost:8080/hello/hi
    public class HelloController {
        @GetMapping(value = {"/say/{id}","/hi/{id}"})  //localhost:8080/hello/say/123 == localhost:8080/hello/hi/123
    public String say(@PathVariable(value = "id") Integer id){  //@PathVarable(value="id") 获取restful路径中的参数 localhost:8080/hello/say/123 id==123
    return id;
    }
      public String say(@RequestParam(value = "id",requied=false,defaultValue="0") Integer id){  //@RequestParam 路径访问形式为带参数 localhost:8080/hello/say?id=123   requied必填  defaultValue默认值
    return id;
    }
    }
  • 相关阅读:
    php array function
    scrum敏捷开发重点介绍
    PHP文件操作
    正则
    PHP面向对象
    PHP数组
    PHP函数参数
    PHP运算符优先级
    PHP判断变量类型和类型转换的三种方式
    PHP变量的传值和引用
  • 原文地址:https://www.cnblogs.com/zhcnblog/p/8891413.html
Copyright © 2011-2022 走看看