方式:

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. SQL 连贯操作 [1]

    一. 连贯入门 查找到 id 为 1,2,3,4 中按照创建时间的倒序的前两位. 在 Home/controller/UserController.class.php 下插入 1.连贯操作入门 $us ...

  2. Python 黑客 --- 001 UNIX口令破解机

    Python 黑客 实战:UNIX口令破解机 使用的系统:Ubuntu 14.04 LTS Python语言版本:Python 2.7.10 V crypt 库是Python内置的库.在UNIX系统使 ...

  3. head first 设计模式 策略模式

    HEAD FIRST:策略模式定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户. 设计模式:定义一系列的算法,把它们一个个封装起来,并且使它们可以相互替换.本 ...

  4. python3-file文件操作

    # Auther: Aaron Fan '''打开文件的模式有三种:r,只读模式(默认).w,只写模式.[不可读:不存在则创建:存在则删除内容:因为会清空原有文件的内容,一定要慎用]a,追加模式.[可 ...

  5. 数据结构 i_love(我喜欢)

    数据结构 i_love(我喜欢) 问题描述 集训队的学长们都怪怪的,如果 A 学长喜欢 B 学长, A 就会把自己的名字改成«I_love_<B 学长的名字>».但是奇怪的学长们很容易移情 ...

  6. sqlplus相关命令

    1.sqlplus 执行后提示输入用户名及密码 2.sqlplus /nolog; 执行后非登录状态进入 3.conn name/password; 以指定用户名及密码登录 4.sqlplus nam ...

  7. delphi xe6 android ListView增加 Header或Footer 的方法

    var  Item1: TListViewItem;begin    Item1 := ListView1.Items.Add;    Item1.Purpose:=TListItemPurpose. ...

  8. Unobrusive Ajax使用

    mark一下:[ASP.NET MVC 小牛之路]14 - Unobtrusive Ajax篇文章,果断记下来,网址: http://www.cnblogs.com/willick/p/3418517 ...

  9. [转]Passing Managed Structures With Strings To Unmanaged Code Part 3

    1. Introduction. 1.1 In part 1 of this series of blogs we studied how to pass a managed structure (w ...

  10. 市场上主流的BI产品的“答案之书”

    本文来自网易云社区. 从20世纪80年代开始,商业智能的定义出现在人们面前,早期商业智能十分基础和杂乱,不仅仅会把数据处理放进去.还包含有一些可视化方面内容等.这个时期的BI主要的功能是支持多维分析和 ...