springboot controller 参数绑定
2019独角兽企业重金招聘Python工程师标准>>>
springboot可以实现前后端参数绑定
普通POST请求
User.java
package cn.ac.iie.bean;import java.util.List;public class Privileges {private String userName;private String authorityType;private List<String> authorityApps;public Privileges(String userName, String authorityType, List<String> authorityApps) {this.userName = userName;this.authorityType = authorityType;this.authorityApps = authorityApps;}public Privileges() {}@Overridepublic String toString() {return "Privileges{" +"userName='" + userName + '\'' +", authorityType='" + authorityType + '\'' +", authorityApps=" + authorityApps +'}';}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getAuthorityType() {return authorityType;}public void setAuthorityType(String authorityType) {this.authorityType = authorityType;}public List<String> getAuthorityApps() {return authorityApps;}public void setAuthorityApps(List<String> authorityApps) {this.authorityApps = authorityApps;}
}
新建UserController.java
@RestController
public class UserController {@Autowiredprivate UserService userService;@PostMapping("/user/add")public Object addUser(User user) {System.out.println(user);return "CREATED";}}
可以直接使用PostMan来模拟发送请求,
POST请求,发送JSON数据格式
新建PrivilegesController.java
@RestController
public class PrivilegesController {@Autowiredprivate PrivilegesService privilegesService;@PostMapping("/privileges/add")public Object privilegesAdd(@RequestBody Privileges2 privileges2) {System.out.println(privileges2);return "success";}}
Privileges.java
package cn.ac.iie.bean;import java.util.List;public class Privileges {private String userName;private String authorityType;private List<String> authorityApps;@Overridepublic String toString() {return "Privileges{" +"userName='" + userName + '\'' +", authorityType='" + authorityType + '\'' +", authorityApps=" + authorityApps +'}';}public String getUserName() {return userName;}public void setUserName(String userName) {this.userName = userName;}public String getAuthorityType() {return authorityType;}public void setAuthorityType(String authorityType) {this.authorityType = authorityType;}public List<String> getAuthorityApps() {return authorityApps;}public void setAuthorityApps(List<String> authorityApps) {this.authorityApps = authorityApps;}
}
bean中包含list,因此需要前端传递数组,后台可以通过spring的@RequestBody直接获取出对应的bean。
postman需要准备的:
- 选post请求
- Headers中添加 key: Content-Type value:application/json
- Body中选raw, JSON(application/json)
- 文本框中写入json参数
{"userName": "vincent","authorityType": "mac","authorityApps": ["1","2"]
}
这样后台就可以收到对象了
转载于:https://my.oschina.net/duanvincent/blog/3058851
springboot controller 参数绑定相关推荐
- usercontroller.java,springboot controller 参数绑定
springboot可以实现前后端参数绑定 普通POST请求 User.java package cn.ac.iie.bean; public class User { private String ...
- Spring Mvc Controller返回值、参数绑定、参数校验 (高级二)
1,Controller 返回值 返回moduleAndView 返回 String 返回void 2,Controller 参数绑定 客户端请求携带的key/value 键值对 绑定到 Contro ...
- Springboot Controller实体属性大写、第二个字母大写无法获取数据
1.首字母大写 建议先看这篇文章 Springboot Controller参数映射之属性首字母小写第二字母大写无法映射问题分析_controller 参数首字母大写_万物皆字节的博客-CSDN博客 ...
- SpringMVC之Controller和参数绑定
在上一篇Spring+SpringMVC+Mybatis整合中说到了SSM的整合,并且在其中添加了一个简单的查询功能,目的只是将整个整合的流程进行一个梳理,下面在上一篇中工程的基础上再说一些关于Spr ...
- springboot实现增量备份_增量同步-spring batch(6)动态参数绑定与增量同步
tags:springbatch 1.引言 上一篇<便捷的数据读写-spring batch(5)结合beetlSql进行数据读写>中使用Spring Batch及BeetlSql,对数据 ...
- springMVC参数绑定与数据回显
简单例子:修改商品信息的jsp页面: 参数绑定过程: 1.2.1 默认支持的参数类型 处理器形参中添加如下类型的参数处理适配器会默认识别并进行赋值. 1.1.1 HttpServletReq ...
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
文章主要讲解request 数据到handler method 参数数据的绑定所用到的注解和什么情形下使用. 简介: handler method 参数绑定常用的注解,我们根据他们处理的Request ...
- springmvc的初始化参数绑定
一.springmvc的初始化参数绑定 此种和我们之前说的类型转换非常相似,可以看作是一种类型转换 在初始化参数绑定时 重要的是参数类型 -------------------单日期的绑定 二. 配 ...
- java元婴期(30)----java进阶(springmvc(4)---参数绑定(下)springmvc校验异常处理)
包装类型pojo参数绑定 需求 商品查询controller方法中实现商品查询条件传入. 实现方法 第一种方法:在形参中 添加HttpServletRequest request参数,通过reques ...
最新文章
- matlab中调用java代码_Matlab中调用第三方Java代码
- spring上下文是什么意思_Java程序员只会CRUD连Spring事务传播机制都不懂?
- mysql2tb_MySQL2
- visual studio学习python_一步一步学Python3(小学生也适用) 第三篇: Visual Studio Code
- 【嵌入式】Modbus TCP功能码
- 液晶显示模块的分类和基本知识
- 献给时尚男女的61句最酷口语(转)
- 泄露你的JavaScript技术很烂的五个表现
- 优秀!Github上10个开源免费的后台控制面板你值得拥有!
- 钰泰ETA6002,2.5A,3MHz开关充电器,带路径管理
- IT人才外包服务的好处?
- js 基础词汇及方法整理
- 风电的Weibull分布及光电的Beta分布组合研究(Matlab代码实现)
- 解剖学坐标体系(LPS , RAS和LAS)
- 微信史诗级更新:60秒长语音有救了!
- cad批量转换低版本如何实现?
- 压缩pdf大小的方法?怎样压缩pdf大小?pdf文档怎么压缩?pdf文件太大怎么压缩?pdf文件太大怎么压缩成小内存?如何降低pdf文件大小?怎么把pdf文件压缩到指定大小?压缩pdf的简单方法
- 身在异国的你,心目中是否有张“不可取代名单”?
- Django简洁留言板系统
- 程序员久坐太累,用BTU模组和液晶屏改造了一款智能呼啦圈!
热门文章
- 安全可控、依法合规 人工智能落地金融领域“讲原则”
- GPT-3开始探索付费使用:每月700块,写得比莎士比亚还多
- SAP QA32试图做UD,系统报错-工厂 BTYC中的 QM 基选设置需要维护
- 高铁转地铁不想重复安检?多地已有举措
- 港片中十个难以超越的经典人物形象
- 【干货】人工智能工程师的三个层次
- 《数学之美》第2章自然语言处理从规则到统计
- torch.meshgrid
- (linux) Firefox is already running, but is not responding解决方法
- 使用Fair kripke来判断kripke的可达性和可避免性