SpringBoot:前端提交数据,服务端无法获取数据

复制代码
http://www.xxx.com?phone=111111111111&code=1332

上述访问传值方式为键值对方式,服务端springmvc获取 >>

复制代码
// 在HttpServlet实现类的doGet、doPost方法中获取前端传来的值
doGet(ServerHttpRequest request){
    String phone = request.getParameter("phone");
}

// controller 中获取
saveInfo(String phone){
    System.out.println(phone)
}

如果在springcloud网关中集中处理,获取值如下

复制代码
public class ValidateCodeGatewayFilter extends AbstractGatewayFilterFactory {

	@Override
	public GatewayFilter apply(Object config) {
		return (exchange, chain) -> {

			ServerHttpRequest request = exchange.getRequest();
          	String mobile = request.getQueryParams().getFirst("mobile");
            String code = request.getQueryParams().getFirst("code");

			return chain.filter(exchange);
		};
	}
}

如果传输的值为 body如下图 >>

这个时候我们服务端获取值的时候需要添加*@RequestBody,@RequestBody*主要用来接收前端传递给后端的json字符串中的数据的(请求体中的数据的);而最常用的使用请求体传参的无疑是POST请求了

相关推荐
麦兜*25 分钟前
Spring Boot启动优化7板斧(延迟初始化、组件扫描精准打击、JVM参数调优):砍掉70%启动时间的魔鬼实践
java·jvm·spring boot·后端·spring·spring cloud·系统架构
Coding小公仔35 分钟前
C++ bitset 模板类
开发语言·c++
KK溜了溜了43 分钟前
JAVA-springboot 整合Redis
java·spring boot·redis
小白变怪兽1 小时前
一、react18+项目初始化(vite)
前端·react.js
ai小鬼头1 小时前
AIStarter如何快速部署Stable Diffusion?**新手也能轻松上手的AI绘图
前端·后端·github
小赖同学啊1 小时前
物联网数据安全区块链服务
开发语言·python·区块链
天河归来1 小时前
使用idea创建springboot单体项目
java·spring boot·intellij-idea
shimly1234561 小时前
bash 脚本比较 100 个程序运行时间,精确到毫秒,脚本
开发语言·chrome·bash
weixin_478689761 小时前
十大排序算法汇总
java·算法·排序算法