总纲:
无论你传的参数是什么样的,最后mybtis都会将你传入的转换为map的
方式1
接口
/**
* 通过userid,ParentID获取 List<Menu>
*/
public List<Menu> getMenus(String parID,Integer userId);
映射文件
<select id="getMenus" resultMap="menu" >
select
MenuID,
Title,
ParentID,
PageUrl,
Sequence,
IsLeaf,
IconName,
IsActive,
PrivilegeID,
CreateDate,
CreateBy,
ModifyDate,
ModifyBy
from Menu
where UserID=#{0}
and ParentID=#{1}
</select>
方式2基于注解
接口
/**
* 通过userid,ParentID获取 List<Menu>
*/
public List<Menu> getMenus( @Param("parentID")String parID,@Param("uid")Integer userId);
映射文件
<select id="getMenus" resultMap="menu" >
select
MenuID,
Title,
ParentID,
PageUrl,
Sequence,
IsLeaf,
IconName,
IsActive,
PrivilegeID,
CreateDate,
CreateBy,
ModifyDate,
ModifyBy
from Menu
where UserID=#{uid}
and ParentID=#{parentID}
</select>
方式3 Map封装多参数
接口
/**
* 通过userid,ParentID获取 List<Menu>
*/
public List<Menu> getMenus(Map<String,Object> map);
映射文件
<select id="getMenus" resultMap="menu" >
select
MenuID,
Title,
ParentID,
PageUrl,
Sequence,
IsLeaf,
IconName,
IsActive,
PrivilegeID,
CreateDate,
CreateBy,
ModifyDate,
ModifyBy
from Menu
where UserID=#{userID}
and ParentID=#{parentID}
</select>
方式4 List封装
接口
/**
* 通过userid,ParentID获取 List<Menu>
*/
public List<Menu> getMenus(List<String> lists);
映射文件
<select id="getMenus" resultMap="menu" >
select
MenuID,
Title,
ParentID,
PageUrl,
Sequence,
IsLeaf,
IconName,
IsActive,
PrivilegeID,
CreateDate,
CreateBy,
ModifyDate,
ModifyBy
from Menu
where ParentID in
<foreach item="parentID " index="index" collection="list" open="(" separator="," close=")">
#{parentID }
</foreach>
</select>