SpringMVC 使用对象接收 GET 请求参数 QueryString
SpringMVC Spring Boot About 393 words需求
将问号后的请求参数封装到对象中。
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;
}
Views: 1,666 · Posted: 2022-10-22
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓
Loading...