Optional int parameter 'fundID' is present but cannot be translated into a null value due to being declared as a primitive type

错误的意思是: "可选的int参数'fundID'存在但由于被声明为基本类型而无法转换为空值"

意思是fundID被申明为int的基本数据类型, 不能转换为字符串的null值. 难道是在参数调用

的时候, 需要把fundID设置为对象类型吗? 答案是正确的. 

    @RequestMapping(value = "/fund-purchase")
    public String fundPurchase(int fundID) {
        Fund fund = fundService.selectFundByID(1);
        System.out.println("fund: " + fund);
        return null;
    }

解决办法: int 改为 Integer,

                前端通过url传递过来的数据, 改为对象类型

    @RequestMapping(value = "/fund-purchase")
    public String fundPurchase(Integer fundID) {
        Fund fund = fundService.selectFundByID(1);
        System.out.println("fund: " + fund);
        return null;
    }

问题解决!

原文地址:https://www.cnblogs.com/zjulanjian/p/11079784.html