zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    协程初探
    属性传值
    分析代理模式
    上下文菜单与TrackPopupMenu
    走进小作坊(十六)----口碑营销
    线程池QueueUserWorkItem
    exosip
    Spark Core源代码分析: Spark任务运行模型
    微软2014校园招聘笔试试题
    怎样配置Tomcat环境变量
  • 原文地址:https://www.cnblogs.com/flywang/p/6739374.html
Copyright © 2011-2022 走看看