Mybatis中传参数的方法

1.使用注解绑定,mapper.xml 对应方法 不需要指定 parameterType,(推荐使用注解绑定方式)

方法接口:

List<CalculateIdeacommissionsum> selectByExample(@Param("example") CalculateIdeacommissionsum example,@Param("roleNameList") List<String> roleNameList);

方法对应的Mapper.xml

<!--  通过userStatus 排序查询 升序    -->
<select ; font-size: 15px'></select>
2.如果接口参数没有使用注解绑定,mapper.xml 对应方法 需要指定对应的参数类型。

List<CalculateIdeacommissionsum> selectByExample(CalculateIdeacommissionsum example);

方法对应的Mapper.xml

<!--  通过userStatus 排序查询 升序    -->
<select ; font-size: 15px'></select>

3. parameterType 也可以使用Map存放参数进行查询

接口方法:

List<BaseEmpinfo> selectByParam(Map<String,String> map);

接口方法对应的Mapper.xml 文件方法:

<select 分隔开。
<if test="roleNameList!=null and roleNameList.size()&gt; 0">
<foreach collection="roleNameList" item="rolename" separator="," open="and rolename in(" close=")">
#{rolename,jdbcType=VARCHAR}
</foreach>
</if>
sql如下:

select * from Calculate_IdeaCommissionSum where calculateYear=2019 and calculateMonth=2 and roleName  in ('副总经理','总监','经纪人');

将roleName的多个条件用关系转化为 roleName in (roleName1,roleName2,roleName3...)  in中用foreach循环

参考博客:https://jingyan.baidu.com/album/00a07f3873520e82d028dcce.html?picindex=1

相关文章: