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>
  • 相关阅读:
    maven-eclipse 中index.html页面乱码
    java-Unsupported major.minor version 52.0错误解决
    eclipse引入httpServlet源码
    eclipse恢复默认布局
    eclipse导入Java源码
    bootstrap fileinput api翻译笔记
    js判断display隐藏显示
    php根据路径获取文件名
    js事件处理-整理
    Jms(消息中间件)两种消息传输方式QUEUE和TOPIC比较
  • 原文地址:https://www.cnblogs.com/fengfuwanliu/p/10645524.html
Copyright © 2011-2022 走看看