接口入参:list入参 和 string入参怎么同时用@RequestBody接收 请用java代码展示
时间: 2024-04-29 12:24:26 浏览: 125
[] - 2022-05-28 @RequestBody 接收数组、List 参数、@Deprecated 标记废弃方法.pdf
可以将list入参和string入参封装成一个对象,然后使用@RequestBody注解接收整个对象。具体代码如下:
```
public class MyRequest {
private List<String> listParam;
private String stringParam;
// getters and setters
}
@RequestMapping("/api")
public void myApi(@RequestBody MyRequest request) {
List<String> listParam = request.getListParam();
String stringParam = request.getStringParam();
// do something
}
```
阅读全文