MyBatis学习_1_ Result Maps collection does not contain value for *

来源:互联网 发布:c语言如何判断闰年 编辑:程序博客网 时间:2024/06/01 13:53

刚刚开始学习mybatis,希望能把在学习过程中的感受和遇到的问题记录下来,以供之后查看也希望能够帮助和我一样的新手。

  1. “ Result Maps collection does not contain value for *“的问题
我这里出现这个问题是因为在查询记录的时候的”resultType“错写成了”resultMap"造成的

<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE mapperPUBLIC "-//mybatis.org//DTD Mapper 3.0//EN""http://mybatis.org/dtd/mybatis-3-mapper.dtd"><!-- 映射文件, parameterType 为在SqlMapConfig.xml中为类起的别名 --><mapper namespace="com.leecode.mybatis.helloworld.Student"><sql id="baseSql">SELECT * FROM</sql><insert id="save" parameterType="Student">INSERT INTO T_STUDENT (NAME, SEX, AGE, NATIVEPLACE) VALUES (#{name}, #{sex}, #{age}, #{nativePlace})</insert><select id="selectOne" parameterType="int" resultType="Student">    <include refid="baseSql"/> T_STUDENT    WHERE ID = #{id}</select><select id="selectAll" resultMap="Student">    <include refid="baseSql"/> T_STUDENT</select></mapper>
需要说明的是,在映射文件中只要有一个resultMap活resultType属性指向错误,在这个文件中的其他正确的语句也不能执行所以在出现以上错误时并不一定是正在执行的语句的错误,也可能是当前文件中其他语句的错误,需要仔细检查,我这里就是因为id为“selectAll”的select标签中的resultType错写成了resultMap造成了错误(见上边的代码)。

原创粉丝点击