Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/dzw1113/multirequest

解决RequestBody注解无法支持多个参数问题,传统形式必须封装对象,导致对象泛滥。同时解决request流反复读问题
https://github.com/dzw1113/multirequest

java requestbody spring

Last synced: 16 days ago
JSON representation

解决RequestBody注解无法支持多个参数问题,传统形式必须封装对象,导致对象泛滥。同时解决request流反复读问题

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);
```