实体中有一个名为“ carType”的列表类型的属性,该实体如下所示:
public class Car{
private List carType;
private String carName;
public void setCarType(List carType){
this.carType = carType;
}
public List getCarType(){
return carType;
}
}
我在调用DAO接口之前为其分配了一个值,就像:
Car car = new Car();
car.setCarType = [1,2,3];
List list = Dao.car(Car car);
然后我尝试使用mybatis的foreach标签映射参数:
<select id='car'>
select car_name, car_type from tb_car
where car_type in
<foreach item="item" collection="carType" separator="," open="(" close=")" index="">
#{item}
</foreach>
</select>
此外,我希望结果如下:
select car_name, car_type from tb_car
where car_type in (1, 2, 3)
但是调试后发生以下错误:
org.mybatis.spring.MyBatisSystemException: nested exception is
org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException:
invalid comparison: java.util.ArrayList and java.lang.String
### Cause: java.lang.IllegalArgumentException: invalid comparison:
java.util.ArrayList and java.lang.String
我知道我可以使用Hashmap类型的参数修复它,但是您能告诉我如何以这种方式更正我的代码吗?
答案 0 :(得分:1)
参数是列表类型吗?尝试<select id='car' parameterType="java.util.List">
还是Car
类型?尝试<select id='car' parameterType="your.class.package.Car">