在使用mybatis框架 报这个错误时, 是mapper文件中,查询语句的返回类型写错了,即该用resultType用成了resultMap。 如果你要返回基本类型,或者返回已存在的pojo对象,用resultType修饰。如果要使用resultMap,就需要在mapper.xml文件中用定义出来要返回的字段。
resultMap和resultType的区别:
1、如果返回类型是基本类型,如String,Integer,Long等,用resultType。 或者是已经存在的pojo,可以用resultType,如下:
(1)基本类型:
<select id="countListByCondition" resultType="java.lang.Integer">
<select id="countListByCondition" resultType="java.lang.Long">
(2)自定义的pojo
<select id="countListByCondition" resultType="com.mapp.mdc.core.bo.AppInfo">
2、如果返回类型使用 resultMap,在mapper.xml的文件中需要进行自定义配置后才能使用。
<resultMap id="BaseResultMap" type="com.mapp.mdc.core.bo.AppInfo">
<id column="id" property="id" jdbcType="BIGINT"/>
<result column="app_id" property="appId" jdbcType="BIGINT"/>
<result column="app_name" property="appName" jdbcType="VARCHAR"/>
<result column="type" property="type" jdbcType="TINYINT"/>
<result column="create_time" property="createTime" jdbcType="INTEGER"/>
<result column="update_time" property="updateTime" jdbcType="INTEGER"/>
</resultMap>
设置resultMap标签的id, type是映射对象的全限定名。
column 对应数据库中的字段名,property对应对象中的字段名。
配置好以后, 返回类型可以用resultMap , 如下:
<select id="selectAll" resultMap="BaseResultMap">