SpringMVC 使用对象接收 GET 请求参数 QueryString
SpringMVC Spring Boot 大约 393 字需求
将问号后的请求参数封装到对象中。
http://localhost:8080/hello?ids=1&ids=2&name=test
Controller
直接将需要转换的对象注入到形参即可。
@RestController
public class HelloController {
@GetMapping("/hello")
public String hello(ReqParam req) {
return "ok-get-" + req.getIds() + "-" + req.getName();
}
}
实体类
@Data
public class ReqParam {
private Set<String> ids;
private String name;
}
阅读 895 · 发布于 2022-10-22
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
Spring Boot 中去除 spring-data-mongodb 自动生成的 _class 字段阅读 4670
-
Tomcat acceptCount 和 maxConnections 参数解析阅读 3786
-
走进 Rust:常量、变量、可变性、Shadowing阅读 3074
-
Charles 提示 SSL Proxying not enabled for this host阅读 9658
-
GoJS 更改 Overview 的拖动框颜色阅读 1566
-
Java 无法 debug Finalizer 类阅读 209
-
PostgreSQL 判断字符串中是否含有指定字符阅读 103
-
Arthas 使用 monitor 在指定时间段内统计方法的调用次数、平均返回时间等阅读 4204
-
Redis 命令行显示中文阅读 3673
-
Spring Boot 注入 Filter 过滤器的几种方式阅读 760