Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dzw1113/multirequest
解决RequestBody注解无法支持多个参数问题,传统形式必须封装对象,导致对象泛滥。同时解决request流反复读问题
https://github.com/dzw1113/multirequest
java requestbody spring
Last synced: 16 days ago
JSON representation
解决RequestBody注解无法支持多个参数问题,传统形式必须封装对象,导致对象泛滥。同时解决request流反复读问题
- Host: GitHub
- URL: https://github.com/dzw1113/multirequest
- Owner: dzw1113
- Created: 2021-07-21T03:03:55.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-07-21T07:56:42.000Z (over 3 years ago)
- Last Synced: 2024-10-10T17:23:28.698Z (about 1 month ago)
- Topics: java, requestbody, spring
- Language: Java
- Homepage:
- Size: 69.3 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Getting Started
maven引用
```
io.github.dzw1113
multirequest
1.0.1```
---
@RequestBody:并不能支持多个参数,当有多个参数时,必须封装成对象,较麻烦@MultiRequestBody:支持关系映射、多参数(基础类型、集合、对象),支持Spring Validated校验。支持Swagger2的话,需要额外配置代码。
用法:
在controller方法种直接引用:```
public HttpResult get(@MultiRequestBody HdTodayReviewQueryPO hdTodayReviewQueryPO)public HttpResult check(@MultiRequestBody(required = true) Long id, @MultiRequestBody(required = true) String operationCode) {
```---
过滤器:BodyFilter,支持反复读取Request里的流,需自己注入到FilterRegistrationBean里。
注入:
```
@Bean
@Order(3)
public FilterRegistrationBean Filters() {
FilterRegistrationBean registrationBean = new FilterRegistrationBean();
registrationBean.setFilter(new BodyFilter());
registrationBean.addUrlPatterns("/*");
registrationBean.setAsyncSupported(Boolean.TRUE);
registrationBean.setName("bodyFilter");
return registrationBean;
}
```
取法:```
HttpServletRequest request = servletRequestAttributes.getRequest();
jsonBody = IOUtils.toString(request.getInputStream(), StandardCharsets.UTF_8);
RequestUtils.getRequest().setAttribute("JSON_REQUEST_BODY", jsonBody);
```