结果:
返回集定义为集合时,返回值为Empty,而不为null;返回值为对象时,为null
验证:
select语句:
<select id="listNone" resultType="Product">select * from product_where name = #{name}</select>
数据库:
测试用例(List集合):
String resource = "mybatis-config.xml";InputStream inputStream = Resources.getResourceAsStream(resource);SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);SqlSession session = sqlSessionFactory.openSession();Map<String,Object> params = new HashMap<>();params.put("name","???");List<Product> out = session.selectList("listNone",params);System.out.println(out == null);System.out.println(out.isEmpty());mit();session.close();
测试结果:
测试用例(返回对象):
Product p = session.selectOne("listNone",params);System.out.println(p == null);System.out.println(p);