1. 程式人生 > >Cannot generate variable name for non-typed Collection parameter type] with root cause

Cannot generate variable name for non-typed Collection parameter type] with root cause

1.問題描述:

前端在呼叫後端的時候,報500  nested exception is java.lang.IllegalArgumentException: Cannot generate variable name for non-typed Collection parameter type] with root cause異常:

經查詢翻譯:大概解釋說是無法生成非型別化集合引數型別的變數名稱,

我的controller層程式碼如下:根據上述判斷為我的請求接收引數cartList異常,而後判斷是要加泛型,這樣請求引數cartList才能完成對映接收關係,否則,其內部元素找不到匹配的型別;

@RestController
@RequestMapping("cart")
public class CartController {

    @Reference
    private CartService cartService;

    @RequestMapping("addItemToCartList")
    public LoginResult addItemToCartList(@RequestBody List cartList, Long itemId, Integer num){
        cartList = cartService.addItemToCartList(cartList, itemId, num);
        LoginResult result = new LoginResult(true,null,cartList);
        return result;
    }

2.解決方案:

在List後加泛型進行約束,當然,這個看你自己具體的程式碼. 

addItemToCartList(@RequestBody List<Cart> cartList, Long itemId, Integer num)

完美解決問題!