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

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

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

已经做判断了

and name like #{productType.name}

而且直接用 select * from ProductType 查询,冒同样的错误

追答


这判断应该是有问题,我不知道Mybatis支不支持这么写,
我觉得你不加这个判断,
a.setName("");//////////////////////////////注意这里
给它set个空值试一下。

温馨提示:答案为网友推荐,仅供参考
相似回答