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请求了

相关推荐
头发多多程序媛1 分钟前
全栈开发入门学习指南(前端)
前端·后端
郝学胜-神的一滴1 分钟前
深度拆解Python迭代协议:从底层原理到核心实践,解锁异步编程的基石
java·网络·python
码云数智-大飞2 分钟前
前端性能优化实战:如何大幅减少应用加载时间?
java
Memory_荒年2 分钟前
SpringBoot 3.x 新特性:让代码自己“996”,你准时下班!
java·后端·spring
Yang-Never2 分钟前
AI Code -> Windows电脑安装Claude
开发语言·windows·git
Irene19914 分钟前
2026 前端开发 Windows 安装 Git 配置指南(有实际安装过程参考:适配版本 the latest 2.53.0(2) x64 )
前端·windows·git
天下无敌笨笨熊8 分钟前
C#异步开发探微
开发语言·c#
后端AI实验室9 分钟前
等保三级整改,敏感数据加密,数十个系统——3个人用Cursor一周搞定了
java·ai
qq_3340602111 分钟前
spring_springmvc_mybatis权限控制+boostrap实现UI
java·spring·mybatis
2301_7938046911 分钟前
C++中的访问者模式变体
开发语言·c++·算法