关于#java#的问题:String类型怎么转换为List <java.long.Integer>类型

问题遇到的现象和发生背景

img

问题相关代码,请勿粘贴截图
        if (id!=null){
            try {
                p = productDaoimpl.selectById(id);
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

运行结果及报错内容

img

img

我的解答思路和尝试过的方法

使用Integer.parseInt不行

Integer.parseInt这个方法只能转为int类型,但是你参数是List类型。

productDaoimpl.selectById(id);

你要搞清楚,参数到底想要Integer类型还是List类型。
看方法意思,是要Integer类型,把对应方法形参类型修改一下。

可先将string 转为 Integer 类型。再加到list里面去

你的selectById 参数是要传一个List吗?报错里面提示了,id是String类型,而selectById 要接收一个List的类型。如果你只要单个id作参数,selectById的参数列表就要修改

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632
if (id!=null){
    try {
        p = productDaoimpl.selectById(Arrays.asList(Integer.valueOf(id)));
    } catch (SQLException e) {
        e.printStackTrace();
    }
}