首页 > 技术文章 > Mybatis多条件查询

lhfyy 2014-10-24 09:59 原文

在Mybatis多条件查询中:

1.参数如果是多条件,则需要将将添加到Map集合中进行传入。

2.就是将其参数用有序数字进行代替。

 

Mybatis单个String类型参数传递

mysql文如下,传入参数为‘parentCategoryId’,运行报错为:There is no getter for property named 'parentCategoryId' in 'class java.lang.String

 

 

<select id="selectCategoryList"  parameterType="java.lang.String" resultType="MstCategoryBean">   

 SELECT         category_id             AS  categoryId,          category_name           AS  categoryName,          view_orderby            AS  viewOrderby      FROM          mst_category      WHERE          del_flg =0      <if test="parentCategoryId!=null  and parentCategoryId!=''">      and          parent_category_id = #{parentCategoryId}      </if>  </select>  

 

发现不能将参数设为bean里的名称,如果传入类型为String类型,则参数需统一修改为[_parameter],修改后的sql语句如下(不管你的参数是什么,都要改成"_parameter" 

 

      <select id="selectCategoryList" parametertype="java.lang.String" resulttype="MstCategoryBean">         

 SELECT              category_id             AS  categoryId,              category_name           AS  categoryName,              view_orderby            AS  viewOrderby          FROM              mst_category          WHERE              del_flg =0                    and             parent_category_id = #{_parameter}     

</select>  

推荐阅读