最终映射的字段名 会被作为 hashMap 的 key ,
<!-- TODO 测试返回 HashMap--> <resultMap id="testResultMap" type="java.util.HashMap"> <result column="id" property="id" jdbcType="INTEGER" javaType="int" /> <result column="campaign_id" property="value" jdbcType="INTEGER" javaType="int" /> </resultMap>
<!-- TODO 返回 List<hashMap> 测试 --> <select id="testQueryHashMap" resultMap="testResultMap" > select id, campaign_id from report_campaign </select>
@Test public void testQueryHashMap() { CampaignReportMapper campaignReportMapper = sqlSession.getMapper(CampaignReportMapper.class); List<Map<String,Object>> result = campaignReportMapper.testQueryHashMap(); for(int i=0; i< result.size(); i++){ Map<String,Object> tmp = result.get(i); System.out.println("id : " + tmp.get("id")); System.out.println("campaign_id : " + tmp.get("campaign_id")); System.out.println("------------------ "); System.out.println("id : " + tmp.get("id")); System.out.println("campaign_id : " + tmp.get("value")); System.out.println("------------------ "); } }
原文地址:https://www.cnblogs.com/ynhk/p/9961528.html
时间: 2024-11-14 15:40:47