zoukankan      html  css  js  c++  java
  • Springboot接收参数

    接收参数有三个方法。

    1、接收id的方法:

    @RestController
    public class ControllerTest {
    
    
        //在这里读取配置文件
        @Autowired
        private Testconfig testconfig;
        //访问路径:http://localhost:8080/hello/5
        @GetMapping(value = "/hello/{id}")
        public String hello(@PathVariable("id") Integer id){
            return "ID:" + id;
        }
    }

    2、接收参数:

    @RestController
    public class ControllerTest {
    
    
        //在这里读取配置文件
        @Autowired
        private Testconfig testconfig;
        //访问路径:http://localhost:8080/hello?id=1551
        @GetMapping(value = "/hello")
        public String hello(@RequestParam("id") Integer id){
            return "ID:" + id;
        }
    }

    也可以这样设置,当不传输参数的时候,默认为5:

        //访问路径:http://localhost:8080/hello?id=1551
        @GetMapping(value = "/hello")
        public String hello(@RequestParam(value = "id", required = false, defaultValue = "5") Integer id){
            return "ID:" + id;
        }
  • 相关阅读:
    开发mis系统的技术
    Navicat软件与pymysql模块
    5.6作业
    mysql表的查询
    5.5作业
    约束条件
    mysql基本数据类型
    数据库
    网络编程项目
    并发编程四
  • 原文地址:https://www.cnblogs.com/suiyisuixing/p/8485647.html
Copyright © 2011-2022 走看看