2016-07-22 40 views
2

我正在使用spring boot 1.3.6實現一個web服務。在我的控制,我有這樣的方法:在一個類中收集多個查詢參數

@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) { ... } 

但它確實不行。我在上面的課上得到了id,但是沒有上課。在Spring請求中收集請求參數的正確方法是什麼?

回答

1

你應該補充的是實現了Spring org.springframework.core.convert.converter.Converter <字符串自定義轉換,EmployeeParams>和使用Spring註冊。

請參閱Spring documentation
This stack overflow issue還討論了添加自定義轉換器或格式器的一些細節。

相關問題