xml代码:
<select id="findMenuListByRole" resultType="java.util.Map" parameterType="java.util.List">
select r.`name` as roleName,GROUP_CONCAT(distinct(m.`name`) SEPARATOR ' | ') as menuList
from sys_role_menu as rm LEFT JOIN sys_role as r on rm.role_id=r.id LEFT JOIN sys_menu as m on rm.menu_id=m.id
where m.name not like '功能菜单' and r.id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
GROUP BY r.`name`
</select>
java代码:
public List<Map<String, String>> findMenuListByRole(List roleIDList);
需要注意的点:
1、resultType=”java.util.Map” 返回值类型
2、parameterType=”java.util.List” 输入的参数
3、将group的值拼接起来 GROUP_CONCAT(distinct(m.`name`) SEPARATOR ‘ | ‘) ;GROUP_CONCAT 有长度限制,group_concat_max_len
4、in的用法
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
5、java代码是要注意
List<Map<String, String>>
而不单单是map
6、#相当于对数据 加上 双引号,$相当于直接显示数据