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的文档内容比较多,翻译工作注定是长期的,毕竟个人能力有限,但为了加 ...
随机推荐
- vue插件开发与发布
vue插件的规范 / plug.js Toast={}Toast.install=function(){ Vue.prototype.$toast=function(){ }} // 导出这个对象 e ...
- Excel VBA 若要在64位系统上使用,则必须更新此项目中的代码,请检查并更新Declare语句,然后用PtrSafe属性标记它们
在Office 2010 32位上开发的Excel VBA系统,迁移到Office 2010 64位下面,打开后使用,报下面错误: 解决办法: 在Declare 后面加PtrSafe 进行标记
- 存储前set方法相互关联 只关联了一方 分别set
17:51:45,580 ERROR SqlExceptionHelper:129 - Column 'lkm_cust_id' cannot be nullorg.hibernate.excepti ...
- [转载]/etc/security/limits.conf解释及应用
limits.conf的格式如下: username|@groupname type resource limit username|@groupname:设置需要被限制的用户名,组名前面加@和用户名 ...
- ARC102D All Your Paths are Different Lengths
传送门 题目大意 让你构造一个有向图,使得从1到n有L条不同路径且长度分别是0~L-1. 分析 我们不难想到每一对相邻点之间连一条权值为0的边,之后二进制分解,将每一对点之间连一个权值为2^i的边,但 ...
- Luogu 1514 [NOIP2010] 引水入城
我就是过来开心一下……这道题从开坑以来已经堆积了大半年了……今天才发现广搜一直写挂…… 丢个线段覆盖的模板,设$f_{i}$表示覆盖区间[1, i]的最小代价,$g_{i, j}$表示覆盖区间[i, ...
- 红帽rhel7.1usbguard
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/security_guide/sec-usi ...
- 自己写的Log记录组件
常规的Debug组件的封装,然后加了一个文件log,分异步和同步(可跨平台使用). /// <summary> /// 常用IO操作类 /// </summary> publi ...
- C# 三元运算
x=,y=; z=x>y? : 结果z= x=,y=; z=x>y? : 结果z=
- Transfer data to SQL Server from SPC-Light with Excel macros
公司的QA检测软件SPC-Light,需要从其中读取一些信息至SQL Server数据库,储存或是做其它分析. 先是在Excel的VBE的工具中,引入一个组件Microsoft ActiveX Dat ...