mybatis 复杂传参

时间:2023-03-10 00:24:00
mybatis 复杂传参

1基本传参数

Public User selectUserWithCon(@param(“userName”)String  name,@param(“userArea”)String area);

对应的Mapper.xml

<select id=" selectUser" resultMap="BaseResultMap">

select  *  from user  where user_name = #{userName} and user_area=#{userArea}

</select>

2 List封装in:

public List<Pojo> getList(List<int> list);

<select id="getList" resultType="Pojo">

  select 字段... from XXX where id in

  <foreach item="item" index="index" collection="list" open="(" separator="," close=")">

    #{item}

  </foreach>

</select>

3 Map封装多参数:

public List<Pojo> geList(HashMap map);

<select id="geList" parameterType="java.util.HashMap" resultType="Pojo">

<!--xxId 是map的key-->

select 字段... from XXX where id=#{xxId}

</select>

4只返回id

<select id="getChildIdByPid" resultType="java.lang.Integer">
select id from content_category where parent_id=#{0};
</select>