我正在使用 spring boot 1.3.6 实现 Web 服务。在我的 Controller 中,我有一个类似的方法:
@RequestMapping(value = "/employees/{id}", method = RequestMethod.PUT)
createEmployee(@PathVariable String id,
@QueryParam(required = false, value = "department") Set<String> departments)
我想在类中收集请求参数,例如:
class EmployeeParams {
public String id;
public Set<String> departments;
}
我尝试使用:
@RequestMapping(value = "/employees/{id}", method = RequestMethod.PUT)
createEmployee(EmployeeParams param) { ... }
但它不起作用。我在上面的类(class)中获得了 id,但不是部门。 Spring请求中请求参数的正确收集方式是什么?
最佳答案
您应该添加一个实现 Spring org.springframework.core.convert.converter.Converter
参见 Spring documentation .
This stack overflow issue还讨论了有关添加自定义转换器或格式化程序的一些细节。
关于java - 在一个类中收集多个查询参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38528187/