spring boot 入参方式
方式:
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 入参方式的更多相关文章
- mybatis入参方式和缓冲
1.mybatis入参方式 @Param注解参数(注解) 封装成对象入参 public int updatePassword(@Param("id")int id,@Param(& ...
- Spring boot 基于注解方式配置datasource
Spring boot 基于注解方式配置datasource 编辑 Xml配置 我们先来回顾下,使用xml配置数据源. 步骤: 先加载数据库相关配置文件; 配置数据源; 配置sqlSessionF ...
- spring boot整合mybatis方式一
方式一: 导入maven依赖: <!--web依赖配置--> <dependency> <groupId>org.springframework.boot</ ...
- Spring Boot入门第四天:使用Thymeleaf模板引擎
原文链接 关于Thymeleaf的优点,我只说一条:它就是html页面啊,直接可以用浏览器打开.受够了JSP的同学可以尝试一下. 1.在pom.xml文件中添加依赖: <!--<depen ...
- Spring Boot 以 war 方式部署
Spring Boot 默认自带了一个嵌入式的 Tomcat 服务器,可以以jar方式运行,更为常见的情况是需要将 Spring Boot 应用打包成一个 war 包,部署到 Tomcat.Jerry ...
- SpringBoot之二:部署Spring Boot应用程序方式
衡量多种部署方式 Spring Boot应用程序有多种构建和运行方式,其中一些你已经使用过了. 在IDE中运行应用程序(涉及Spring ToolSuite或IntelliJ IDEA). 使用Mav ...
- spring boot 学习-创建方式
spring boot是什么 spring boot 是一个快速开发框架,适合小白快速上手开发,它集成了很多优秀的和常用的第三方框架,它简化了xml配置,完全采用注解方式,内部集成了Tomcat.Je ...
- Spring Mvc和Spring Boot读取Profile方式
spring boot java代码中获取spring.profiles.active - u013042707的专栏 - CSDN博客https://blog.csdn.net/u013042707 ...
- Spring Boot 中文参考文档
本人翻译Spring Boot官方文档已经有几天了,虽然不能全天投入,但是间隔一到两天时间还是可以翻译部分内容,Spring Boot的文档内容比较多,翻译工作注定是长期的,毕竟个人能力有限,但为了加 ...
随机推荐
- Java-马士兵设计模式学习笔记-策略模式-模拟Comparable接口
一.情况 1.目标:要在专门用于排序数据的DataSorter.java中实现对所有A类,B类,C类,D类等等的排序 2.初步想法:DataSorter.java的代码如下 public class ...
- R: 常用操作:
################################################### #清除所有变量: rm(list=ls()) #查看变量类型 getwd() setwd() i ...
- python3-列表中存储字典
# Auther: Aaron Fan #示例1:#定义几个字典alien_0 = {"color":"green", "points":5 ...
- 树莓派研究笔记(8)-- 编译lakka v2.1源码
Lakka越玩越觉得强大.如果要是能自己修改一下代码,实现自定义的一些操作就更好了.还可以修复字体文件,修复在部分机器上自动更换Mac地址导致ip变化的问题. 所以我们来尝试编译这个系统.这篇文章几乎 ...
- 3.内网渗透之reGeorg+Proxifier
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAxIAAAE2CAIAAAB6BDOVAAAgAElEQVR4Aey9Z5Aex3X327MRGVzkRH ...
- super-smack
我有个办法,不过不是用LR,是用super-smack,如果只对数据库进行抗压力测试,应该管用.Super-smack 现在是1.3版,源码下载地址如下:http://vegan.net/tony/s ...
- HTML 4.0 触发事件
HTML 4 的新特性之一是可以使 HTML 事件触发浏览器中的行为,比方说当用户点击某个 HTML 元素时启动一段 JavaScript. 在现代浏览器中都内置有大量的事件处理器.这些处理器会监视特 ...
- eclipse workspace 共享设置
总结一下,复制工作空间配置步骤如下: 1 使用eclipse新建workspace. 2 将新建的workspace下的.metadata\.plugins内容全部删除. 3 将需要拷贝的worksp ...
- c#打开关闭进程
private const string FileName = "test.exe"; //进程名称不带扩展名 private const string ProcessName = ...
- asp.net core 之多语言国际化自定义资源文件
先说说 asp.net core 默认的多语言和国际化. 官方文档 一:基本使用方法 先要安装 包 Microsoft.AspNetCore.Mvc.Localization (依赖 Microsof ...