接收参数有三个方法。

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;
}

Springboot接收参数的更多相关文章

  1. SpringBoot接收前端参数的三种方法

    都是以前的笔记了,有时间就整理出来了,SpringBoot接收前端参数的三种方法,首先第一种代码: @RestController public class ControllerTest { //访问 ...

  2. springboot项目--传入参数校验-----SpringBoot开发详解(五)--Controller接收参数以及参数校验----https://blog.csdn.net/qq_31001665/article/details/71075743

    https://blog.csdn.net/qq_31001665/article/details/71075743 springboot项目--传入参数校验-----SpringBoot开发详解(五 ...

  3. SpringBoot Controller接收参数的几种方式盘点

    本文不再更新,可能存在内容过时的情况,实时更新请移步我的新博客:SpringBoot Controller接收参数的几种方式盘点: SpringBoot Controller接收参数的几种常用方式盘点 ...

  4. SpringBoot接收map类型的参数

    如果某个controller的某个接口的参数特别多,也可以使用map的方式来接收参数,接收之后使用get方法获取即可. 1)get请求方式,定义map接收方式 @RequestParam(requir ...

  5. SpringBoot(三):springboot启动参数

    springboot默认启动入口函数是支持接收参数,并且在整个应用程序内部也可以获取到这些参数,并且如果传递的参数是一些内部定义的参数将会被映射到springboot内部配置项,从而达到配置效果. s ...

  6. Spring Boot之 Controller 接收参数和返回数据总结(包括上传、下载文件)

            一.接收参数(postman发送) 1.form表单 @RequestParam("name") String name 会把传递过来的Form表单中的name对应 ...

  7. springboot接收date类型参数

    springboot接收日期类型参数,实现自动转换. 1. 当请求类型为json,date类型字段为 json 字段时,可以使用如下两种方法 1.1. 当前参数加两个注解(有些文章说接收只需要加 @D ...

  8. 探究Spring Boot中的接收参数问题与客户端发送请求传递数据

    结合此篇参考Spring框架学习笔记(9)--API接口设计相关知识及具体编码实现 在使用Spring Boot进行接收参数的时候,发现了许多问题,之前一直都很忙,最近才稍微有空研究一下此问题. 网上 ...

  9. Struts2中Action接收参数的四种形式

    1.Struts2的Action接收参数的三种形式.      a. 使用Action的属性接收(直接在action中利用get方法来接收参数):                   login.js ...

随机推荐

  1. 错误:Caused by:org.apache.spark.SparkException: Kryo serialization failed: Buffer overflow.Available: 0, required: 21. To avoid this,

    这个是写入Redis时用的序列化器,然后错误提示是超过了大小限制,把配置调大即可. .set("spark.kryoserializer.buffer.max","128 ...

  2. 【个人专用&入门级】LAMP一键安装包

    最近自学了下Shell编程,也算是入门吧!按照如下教程,编译安装了LAMP(Apache-2.4.6 + MySQL-5.5.25 + PHP-5.3.27) CentOS6.3编译安装LAMP(1) ...

  3. 【spring data jpa】根据一个时间字段 查询 时间段的处理方法

    处理方法  包含结束时间00.00.00 Date createDate = boxCodeLog.getCreateDate(); if (createDate != null){ LocalDat ...

  4. minishift安装

    先下载安装包 https://github.com/minishift/minishift/releases mac上运行命令 minishift start --vm-driver=virtualb ...

  5. 推送代码分支时出现:fatal: 'origin' does not appear to be a git repository

    关于ubuntu进行提交本地分支到远程库出现问题: 解决方案: 执行如下命令: git remote add origin git@github.com:yourusername/test.git y ...

  6. ElementUI使用问题记录:设置路由+iconfont图标+自定义表单验证

    一.关于导航怎么设置路由 1.在el-menu这个标签的属性中添加 router ,官方文档的解释是:启用vue-router 这种模式 2.在el-menu-item标签中的index属性直接书写路 ...

  7. 推断是否是有效的IP地址

    #include<stdio.h> #include<string.h> bool isValidIp(char *s) { int len=strlen(s); int i= ...

  8. python 实现计算数独

    输入文件格式: 008309100900060004007504800036000540001000600042000970005907300600010008004608200 输出结果: yuan ...

  9. Appium获取安卓页面toast(java版)

    toast是什么?安卓页面上弹出的提示框,这种提示框出现在屏幕上大概3秒左右就会消失.用uiautomatorviewer根本定位不到. 准备环境,Appium版本需要1.6.3以上. 代码 初始化设 ...

  10. Android开发调试常用命令列表

    Android开发调试常用命令列表 adb命令 am am start -n com.iflytek.autofly.account/.ui.MainActivity am start -n com. ...