SpringMVC 數組類型的參數: Cannot generate variable name for non-typed Collection parameter type


我只想安靜的傳個數組類型的參數, 為什么各種報錯...

 

    @DeleteMapping("del")
    @ApiOperation(value = "刪除")
    public Integer deleteMan(@RequestBody List idList) {
  ...

不行, 報錯:

Cannot generate variable name for non-typed Collection parameter type

 

改吧:

    @DeleteMapping("del")
    @ApiOperation(value = "刪除")
    public Integer deleteMan(@RequestBody ArrayList idList) {
  ...

不行, 這回不報錯了,  但是連參數都傳遞不了,  idList 永遠值是空的,,  改成 ArrayList<String> 也是不行的

 

改吧

    @DeleteMapping("del")
    @ApiOperation(value = "刪除")
    public Integer deleteMan(@RequestBody String[] idList) {
  ...

 

還是不行, 再改:

    @DeleteMapping("del")
    @ApiOperation(value = "刪除")
    public Integer deleteMan(String[] idList) {
  ...

這回倒是可以了, 但是, 傳參格式不是原來那樣的...  期望是["aa", "bb"] , 但現在必須是 aa, bb,  而且 aa/bb 不能有引號, 否則就奇怪了.

 

百度看看, 一堆這樣的,  似乎沒有我的答案, 大家都沒遇見過??

 

bing 的結果也差不多...

 

隨便看看吧: 

http://www.docjar.com/html/api/org/springframework/core/Conventions.java.html 

https://blog.csdn.net/z69183787/article/details/52817479?locationNum=7&fps=1

...

好像確實是 后端報錯了: 在 Conventions.java 的這個 地方

  1. if (valueClass == null) {  
  2.                 throw new IllegalArgumentException(  
  3.                         "Cannot generate variable name for non-typed Collection parameter type");  

 

 

改吧: 

    @DeleteMapping("del")
    @ApiOperation(value = "刪除")
    public Integer deleteMan(@RequestBody List<String> idList) {
  ...

 

這回可以了... 恍然大悟.

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM