idea报错-java.lang.IllegalStateException:(数组Arrays.asList())

### Error updating database.  Cause: java.lang.IllegalStateException: Type handler was null on parameter mapping for property '__frch_listItem_2'. It was either not specified and/or could not be found for the javaType ([J) : jdbcType (null) combination.
### Cause: java.lang.IllegalStateException: Type handler was null on parameter mapping for property '__frch_listItem_2'. It was either not specified and/or could not be found for the javaType ([J) : jdbcType (null) combination.] with root cause

java.lang.IllegalStateException: Type handler was null on parameter mapping for property '__frch_listItem_2'. It was either not specified and/or could not be found for the javaType ([J) : jdbcType (null) combination.
	at org.apache.ibatis.mapping.ParameterMapping$Builder.validate(ParameterMapping.java:119) ~[mybatis-3.4.6.jar:3.4.6]
	at org.apache.ibatis.mapping.ParameterMapping$Builder.build(ParameterMapping.java:104) ~[mybatis-3.4.6.jar:3.4.6]

代码:

/**
 *  批量下架
 * @param ids
 * @return
 */
@PutMapping("/pull/many")
public Result pullMany(@RequestBody long[] ids){
    int count = spuService.pullMany(ids);
    return new Result(true,StatusCode.OK,count+"款商品下架成功");
}


/**
 * 批量下架
 * @param ids
 * @return
 */
int pullMany(long[] ids);


/**
 * 批量下架
 * @param ids 需要下架的商品ID集合
 * @return
 */
@Override
public int pullMany(long[] ids) {
    //is_marketable是否上架,0已下架,1已上架
    //is_delete是否删除,0:未删除,1:已删除
    //status审核状态,0:未审核,1:已审核,2:审核不通过
    //批量上架 update tb_spu set is_marketable=1 where id in(ids)and is_delete=0 and is_marketable=0 and status=1
    //批量下架 update tb_spu set is_marketable=0 where id in(ids) and is_delete=0 and is_marketable=1 and status=1

    Spu spu=new Spu();
    spu.setIsMarketable("0");//下架
    Example example=new Example(Spu.class);
    Example.Criteria criteria = example.createCriteria();
    criteria.andIn("id", Arrays.asList(ids));//id
    //上架状态
    criteria.andEqualTo("isMarketable","1");
    //审核通过的
    criteria.andEqualTo("status","1");
    //非删除的
    criteria.andEqualTo("isDelete","0");
    return spuMapper.updateByExampleSelective(spu, example);
}

List<>集合中只能放引用类型,Arrays.asList()不能用于基本数据类型,适用于对象型数据的数组(String、Integer...)

程序运行的结果并是不是我们想要的5,而是1,这是因为asList方法接受的参数是一个可变长度的泛型

而java的8中基本数据类型是不能被泛型化的,其相应的包装类是可以被泛型化的,只有Object及

其子类才可以泛型化。数组是可以被泛型化的,所以此demo输出结果是1,而不是5。

要想输出是5,只需要将int改为Integer

换成Long[] ids即可

/**
 *  批量下架
 * @param ids
 * @return
 */
@PutMapping("/pull/many")
public Result pullMany(@RequestBody long[] ids){
    int count = spuService.pullMany(ids);
    return new Result(true,StatusCode.OK,count+"款商品下架成功");
}


/**
 * 批量下架
 * @param ids
 * @return
 */
int pullMany(long[] ids);


/**
 * 批量下架
 * @param ids 需要下架的商品ID集合
 * @return
 */
@Override
public int pullMany(Long[] ids) {
    //is_marketable是否上架,0已下架,1已上架
    //is_delete是否删除,0:未删除,1:已删除
    //status审核状态,0:未审核,1:已审核,2:审核不通过
    //批量上架 update tb_spu set is_marketable=1 where id in(ids)and is_delete=0 and is_marketable=0 and status=1
    //批量下架 update tb_spu set is_marketable=0 where id in(ids) and is_delete=0 and is_marketable=1 and status=1

    Spu spu=new Spu();
    spu.setIsMarketable("0");//下架
    Example example=new Example(Spu.class);
    Example.Criteria criteria = example.createCriteria();
    criteria.andIn("id", Arrays.asList(ids));//id
    //上架状态
    criteria.andEqualTo("isMarketable","1");
    //审核通过的
    criteria.andEqualTo("status","1");
    //非删除的
    criteria.andEqualTo("isDelete","0");
    return spuMapper.updateByExampleSelective(spu, example);
}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZHOU_VIP

您的鼓励将是我创作最大的动力!

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值