- selectList() 返回值 List<resultType属性控制>
【注意】适用于查询结果都需要遍历的需求
mybatis.xml配置:
<select id="selAll" resultType="com.ouc.pojo.Flower">
select * from flower
</select>
测试类:
List<Flower> list = session.selectList("com.ouc.mapper.FlowerMapper.selAll");
for (Flower flower : list) {
System.out.println(flower.toString());
}
- selectOne() 返回值Object
【注意】适用于返回结果只是变量或一行数据时
mybatis.xml配置:
<select id="selById" resultType="com.ouc.pojo.Flower">
select * from flower where id=1
</select>
测试类:
Flower flower = session.selectOne("com.ouc.mapper.FlowerMapper.selById");
System.out.println(flower);
- selectMap() 返回值Map
【注意】适用于需要在查询结果中通过某列的值取到这行数据的需求
mybatis.xml配置:
<select id="selMap" resultType="com.ouc.pojo.Flower">
select * from flower
</select>
测试类:
Map<Object, Object> map = session.selectMap("selMap", "name");
System.out.println(map);