参考:https://blog.csdn.net/sunshinezx8023/article/details/78403011
在使用MyBatis执行sql语句时,出现如下异常:java.lang.UnsupportedOperationException
sql语句如下: 注意:这里的resultType= “Java.util.List”
<select id="getStudentScore" parameterType="String" resultType="java.util.List">
select score from student_score where student_id=#{student_id,jdbcType=VARCHAR}
</select>
dao接口代码如下:
public List getStudentScore1(String student_id);
public List getStudentScore2(String student_id);
启动调用方法报错 :java.lang.UnsupportedOperationException
错误原因为:resultType是直接表示返回类型的
应该改为: 注意: 这里的resultType=“String” Long改为java.long.Long
<select id="getStudentScore" parameterType="String" resultType="String">
select score from student_score where student_id=#{student_id,jdbcType=VARCHAR}
</select>
原因就在于resultType代表的是List中的元素类型,而不应该是List本身,不要对于dao接口生命的List 就误以为返回的是list,返回的应该是元素本身的类型