批量删除时报错Failed to instantiate [java.util.List]: Specified class is an interface

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/u012211603/article/details/80035615

错误信息:
Failed to instantiate [java.util.List]: Specified class is an interface;

分析:
批量删除时,Controller层参数想传入List<Long> ids,然而如果泛型是基本类型或者String,就会报错。

传入Long[] ids数组就可以解决。

然而我Service层andIdIn方法需要的是List集合,因此,最后的解决方案就是,参数传入Long[] ids,然后通过Arrays.asList()方法转换成List集合。

public int delete(Long[] ids) {
		List<Long> idList = Arrays.asList(ids);
		BrandExample example = new BrandExample();
		example.createCriteria().andIdIn(idList);
		return brandMapper.deleteByExample(example);
	}

猜你喜欢

转载自blog.csdn.net/u012211603/article/details/80035615