mybatis传递多种参数问题

1.实体bean:ProductType
2.字段id,name

ProductType.xml 中定义一个查询,如下:

<parameterMap type="map" id="paramMap">
<parameter property="productType" javaType="com.nd.orm.ProductType" jdbcType="OTHER" />
<parameter property="pageSize" javaType="int" jdbcType="NUMERIC"/>
</parameterMap>

<select id="getScrollPage" parameterMap="paramMap" resultType="com.nd.orm.ProductType">
select * from ProductType where 1=1
<if test="productType.name!=null and productType.name!=''">
and name like #{productType.name}
</if>
</select>

查询:
Map<String,Object> map=new HashMap<String, Object>();
ProductType a=new ProductType();
a.setName("XXXXX");//////////////////////////////注意这里
map.put("productType", a);
map.put("pageSize", 10);
List p= session.selectList("ProductType.getScrollPage", map);

问题:
如果a.setName赋值了,查询没问题

可是如果a没有setName,系统就报错:
Cause: org.apache.ibatis.executor.ExecutorException: There was no TypeHandler found for parameter productType of statement ProductType.getScrollPage
最新回答
梦里花落

2022-04-11 18:11:05

mybatis 没用过,Ibatis 用过一段时间。
报的错就是你传进去的
map.put("productType", a);
productType 参数找不到 对应参数。

如果不像传参数进去可以考虑在 getScrollPage 中加入动态的Where 条件。