zoukankan      html  css  js  c++  java
  • MyBatis探究-----返回Map类型数据

       1.使用@MapKey

         @MapKey:告诉mybatis封装Map的时候使用哪个属性作为Map的key

         Map<K, V>:键是这条记录的主键key,值是记录封装后的javaBean

    1.1 返回单个对象

        接口中方法:

                           @MapKey("empName")
                           public Map<String, Object> getEmpReturnMap2(String empId);

        XML中配置:

    <select id="getEmpReturnMap2" resultType="com.mybatis.entity.Employee">
            select * from t_employee where empId=#{empId}
    </select>

    1.2 返回多个对象

          接口中方法:

                             @MapKey("empId")
                             public Map<String, Object> getEmpsReturnMaps2();

          XML中方法:

    <select id="getEmpsReturnMaps2" resultType="com.mybatis.entity.Employee">
            select * from t_employee
    </select>

       2.不适用@MapKey  

         返回Map:key就是列名,值就是对应的值

    2.1 返回单个Map

         接口中方法:public Map<String, Object> getEmpReturnMap(String empId);

         XML中配置:

    <select id="getEmpReturnMap" resultType="java.util.HashMap">
            select * from t_employee where empId=#{empId}
    </select>

    2.2 返回多个Map

         接口中方法:public List<Map<String, Object>> getEmpsReturnMaps();

         XML中配置:

    <select id="getEmpsReturnMaps" resultType="java.util.HashMap">
            select * from t_employee
    </select>
  • 相关阅读:
    python_linux系统相关配置
    python_字典dict相关操作
    python_传参
    mapreduce 学习笔记
    linux 常用命令
    C++ stringstream介绍,使用方法与例子
    C++/C++11中std::numeric_limits的使用
    C++中string erase函数的使用
    C++中accumulate的用法
    malloc的用法和意义
  • 原文地址:https://www.cnblogs.com/fengfuwanliu/p/10645524.html
Copyright © 2011-2022 走看看