MyBatis使用Map作为返回值

MyBatis使用Map作为返回值

	Map selectResultMap(Integer id);
	

	<select id="selectResultMap" resultType="java.util.Map" parameterType="int">
		select m.id as id,m.username as `name`
		from member m
		where id = #{id}

	select>
	MemberMapper memberMapper = sqlSession.getMapper(MemberMapper.class);

	Map map = memberMapper.selectResultMap(1);
	
	System.out.println(map.get("id")+"\t"+map.get("name"));

测试结果如下:

1561456407004

使用List/作为返回值

	List<Map> selectResultMapGraterTDate(String date);
	<select id="selectResultMapGraterTDate" resultType="java.util.Map" parameterType="String">
		select m.id as id,m.username as `name`
		from member m
		where logindate > #{logindate}
	select>

测试:

	String loginDate = "2019-06-07";
	List<Map> maps = memberMapper.selectResultMapGraterTDate(loginDate);
	
	for (Map map : maps) {
		System.out.println(map.get("id")+"\t"+map.get("name"));
	}	

测试结果如下:
MyBatis使用Map作为返回值_第1张图片

你可能感兴趣的:(mybatis)