一、错误写法,如下:
1、在dao.xml文件中返回值定义为 resultType=“java.util.List” 。
![在这里插入图片描述](http://img.555519.xyz/uploads/20230327/0ffe9292fc33cb971f80256e1fe3b692.jpg)
2、dao层会报错,提示Result type not match…
![在这里插入图片描述](http://img.555519.xyz/uploads/20230327/4be97a83ce7ec6e609d59a5174667995.jpg)
二、正确写法
1、在dao.xml文件中返回值定义为 resultType=“java.lang.String” 。
![在这里插入图片描述](http://img.555519.xyz/uploads/20230327/271e33283ee4d4259d928978ec5e96a3.jpg)
2、dao层报错消失
![在这里插入图片描述](http://img.555519.xyz/uploads/20230327/ff0e5f646edc9154545e8a1d83b2a8f5.jpg)
三、报错原因
- resultType是sql映射文件中定义返回值类型,返回值有基本类型,对象类型,List类型,Map类型等。
- 返回List集合时,需要将resultType的值定义为集合中元素类型,而不是返回集合本身。