方式:

1)、直接写,如public User index2(String name)

2)、@RequestParam

  与直接写的区别是,可以写默认值。

3)、@RequestBody

   因为传入的是String类型的json,所以可以使用String类型,如:@RequestBody String jsonStr

  当然,也可以使用相应的对象类型。

4)、@PathVariable

  url中{}

例子:

1)、直接写

@RestController
public class UserController {
@GetMapping("/index")
public User index(String name) {
log.info("接收:{}",name);
return new User(RandomUtil.randomInt(100),String.format("【入参=String】:%s", name));
}
}

2)、@RequestParam

@GetMapping("/index2")
public User index2(@RequestParam(value="name",defaultValue="World") String name) {
log.info("接收:{}",name);
return new User(RandomUtil.randomInt(100),String.format("【入参=@RequestParam】:%s", name));
}

3)、@RequestBody--String

@RequestMapping("/index3")
public User index3(@RequestBody String jsonStr) {
log.info("接收:{}",jsonStr);
return new User(RandomUtil.randomInt(100),String.format("【入参=@RequestBody(String)】:%s", jsonStr));
}

3)、@RequestBody--对象

@RequestMapping("/index4")
public User index4(@RequestBody User user) {
log.info("接收:{}",user);
return new User(RandomUtil.randomInt(100),String.format("【入参=@RequestBody(对象)】:%s", user));
}

4)、@PathVariable

@RequestMapping("/index5/{id}")
public User index5(@PathVariable("id") long id) {
log.info("接收:{}",id);
return new User(RandomUtil.randomInt(100),String.format("【入参=@RequestBody】:%s", id));
}

spring boot 入参方式的更多相关文章

  1. mybatis入参方式和缓冲

    1.mybatis入参方式 @Param注解参数(注解) 封装成对象入参 public int updatePassword(@Param("id")int id,@Param(& ...

  2. Spring boot 基于注解方式配置datasource

    Spring boot 基于注解方式配置datasource 编辑 ​ Xml配置 我们先来回顾下,使用xml配置数据源. 步骤: 先加载数据库相关配置文件; 配置数据源; 配置sqlSessionF ...

  3. spring boot整合mybatis方式一

    方式一: 导入maven依赖: <!--web依赖配置--> <dependency> <groupId>org.springframework.boot</ ...

  4. Spring Boot入门第四天:使用Thymeleaf模板引擎

    原文链接 关于Thymeleaf的优点,我只说一条:它就是html页面啊,直接可以用浏览器打开.受够了JSP的同学可以尝试一下. 1.在pom.xml文件中添加依赖: <!--<depen ...

  5. Spring Boot 以 war 方式部署

    Spring Boot 默认自带了一个嵌入式的 Tomcat 服务器,可以以jar方式运行,更为常见的情况是需要将 Spring Boot 应用打包成一个 war 包,部署到 Tomcat.Jerry ...

  6. SpringBoot之二:部署Spring Boot应用程序方式

    衡量多种部署方式 Spring Boot应用程序有多种构建和运行方式,其中一些你已经使用过了. 在IDE中运行应用程序(涉及Spring ToolSuite或IntelliJ IDEA). 使用Mav ...

  7. spring boot 学习-创建方式

    spring boot是什么 spring boot 是一个快速开发框架,适合小白快速上手开发,它集成了很多优秀的和常用的第三方框架,它简化了xml配置,完全采用注解方式,内部集成了Tomcat.Je ...

  8. Spring Mvc和Spring Boot读取Profile方式

    spring boot java代码中获取spring.profiles.active - u013042707的专栏 - CSDN博客https://blog.csdn.net/u013042707 ...

  9. Spring Boot 中文参考文档

    本人翻译Spring Boot官方文档已经有几天了,虽然不能全天投入,但是间隔一到两天时间还是可以翻译部分内容,Spring Boot的文档内容比较多,翻译工作注定是长期的,毕竟个人能力有限,但为了加 ...

随机推荐

  1. [poj2318]TOYS(直线与点的位置关系)

    解题关键:计算几何入门题,通过叉积判断. 两个向量的关系: P*Q>0,Q在P的逆时针方向: P*Q<0,Q在P的顺时针方向: P*Q==0,Q与P共线. 实际就是用右手定则判断的. #i ...

  2. iOS 本地加载js文件

    #import "RootViewController.h" @interface RootViewController ()<UIWebViewDelegate> @ ...

  3. vmtools!HashTable_GetNumElements+0x5c17

    vmtools!HashTable_GetNumElements+0x5c17 vmtools 应该就是虚拟机和主机通信的问题. HashTable_GetNumElements好想也出错了.

  4. unix 下 shell 遍历指定范围内的日期

    UNIX下遍历日期,date 没有 -d 的参数,所以需要自己处理. 下面使用时差的方法进行计算,遍历的日期是降序的 #!/usr/bin/ksh . $HOME/.profile timelag= ...

  5. MediaRecorder录像那些事

    最近在做一个项目需要运用到MediaRecorder的API,之前都没接触过这部分,开始着手弄的时候各种各样的问题,真是让人崩溃呀! 最后通过网上的资料和大神的指点,当然也有自己几天坚持不懈的努力,终 ...

  6. Arcgis android 10.2安装方法

    请仔细对照博文做!!! 将arcgis android 10.2的压缩包解压 arcgis android 10.2下载地址http://pan.baidu.com/s/1sj2LKO9 Help-& ...

  7. [raspberry pi3] raspberry 充当time machine

    之前是用硬盘直接当timemachine的,看到有人用raspberry+硬盘充当timemachine的 自己的也搞了下,还是蛮方便的,下面是具体的步骤 1.安装必要的服务 sudo apt-get ...

  8. CSS预处理器(SASS和LESS)

    Sass框架应用Sass简介 Sass又名SCSS,是CSS预处理器之一,它能让你更好更轻松的工作.Sass官网是这样描述Sass的:**Sass是一门高于CSS的元语言,能用来清晰的.结构化地描述文 ...

  9. tomcat的日志文件权限与启动用户的权限不一致

    用户work的文件权限(umask=0002)为 u=rwx,g=rwx,o=rx 但是tomcat的日志文件的权限却是:为什么会不一样呢? 这是因为tomcat在启动(catalina.sh)时会重 ...

  10. R-CNN

    标题:<Rich feature hierarchies for accurate object detection and semantic segmentation> 时间:2014 ...