本文共 1439 字,大约阅读时间需要 4 分钟。
如果返回值是一个集合,resultType并非指定为集合类型,而是指定为集合内元素的类型
比如:
List selectAll();
select * from tb_user
测试:
@Testpublic void test01() { List list = tbUserMapper.selectAll(); System.out.println(list);}
比如:
Map selectById(@Param("id") Long id);
select * from tb_user where id = #{id}
测试:
@Testpublic void test02() { Map map = tbUserMapper.selectById(1L); System.out.println(map);}
输出结果:
{ password=123456, update_time=2019-04-04 22:58:26.0, create_time=2019-04-04 22:58:26.0, phone=13100001111, id=1, username=kobe}
@MapKey("id")Map selectMap();
select * from tb_user
测试:
@Testpublic void test03() { Map map = tbUserMapper.selectMap(); for (Long id : map.keySet()) { System.out.println(id + "--->" + map.get(id)); }}
输出:
1--->{ password=123456, update_time=2019-04-04 22:58:26.0, create_time=2019-04-04 22:58:26.0, phone=13100001111, id=1, username=kobe}5--->{ password=123456, update_time=2021-01-31 11:44:22.0, create_time=2021-01-31 11:44:22.0, phone=13011112222, id=5, username=t-mac}6--->{ password=123456, update_time=2021-01-31 11:44:56.0, create_time=2021-01-31 11:44:56.0, phone=13011112222, id=6, username=t-mac}
转载地址:http://wsrv.baihongyu.com/