mybatis和返回

1、查询int 数组

dao类:

public List<Integer> queryRoleIdList(Integer userId);

service类:

List<Integer> userIdList=userRoleService.queryRoleIdList(userId);

<select id="queryRoleIdList" resultType="int">
select
role_id
from
userbase_role
where
user_id=#{userId}
</select>

查询出的结果为[x,y];

2、mybatis  使用in

dao类:

public List<RoleResourceBean> queryByRoleId(List<Integer> list);

service类:

/**
* 根据用户角色获取用户权限
* @param roleId
* @return
*/
public List<RoleResourceBean> queryByRoleId(List<Integer> list){
return dao.queryByRoleId(list);
}

mybatis:

<select id="queryByRoleId" resultMap="roleResourceMap" parameterType="java.util.List">
select
id,
<include refid="requiredColumn" />
from
role_module
where
role_id in
<foreach item="item" index="index" collection="list" open="(" separator="," close=")">
#{item}
</foreach>
</select>

 结果为select * from table where id in(x,y)

参考:http://www.cnblogs.com/mingyue1818/p/3714162.html

原文地址:https://www.cnblogs.com/flywang/p/6739374.html