MyBtais错误:org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.a

Cause: java.lang.ClassNotFoundException: Cannot find class: BaseResultMap
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1455)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:871)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:813)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:730)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireByType(AbstractAutowireCapableBeanFactory.java:1184)
    ... 77 more
    Caused by: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'BaseResultMap'.  Cause: java.lang.ClassNotFoundException: Cannot find class: BaseResultMap
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:117)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.parse(XMLMapperBuilder.java:89)
    at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:464)
    ... 90 more
Caused by: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'BaseResultMap'.  Cause: java.lang.ClassNotFoundException: Cannot find class: BaseResultMap
    at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:100)
    at org.apache.ibatis.builder.xml.XMLStatementBuilder.parseStatementNode(XMLStatementBuilder.java:69)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:132)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.buildStatementFromContext(XMLMapperBuilder.java:125)
    at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement(XMLMapperBuilder.java:115)
    ... 92 more
Caused by: org.apache.ibatis.type.TypeException: Could not resolve type alias 'BaseResultMap'.  Cause: java.lang.ClassNotFoundException: Cannot find class: BaseResultMap
    at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:114)
    at org.apache.ibatis.builder.BaseBuilder.resolveAlias(BaseBuilder.java:127)
    at org.apache.ibatis.builder.BaseBuilder.resolveClass(BaseBuilder.java:98)
    ... 96 more
Caused by: java.lang.ClassNotFoundException: Cannot find class: BaseResultMap
    at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:188)
    at org.apache.ibatis.io.ClassLoaderWrapper.classForName(ClassLoaderWrapper.java:87)
    at org.apache.ibatis.io.Resources.classForName(Resources.java:254)
    at org.apache.ibatis.type.TypeAliasRegistry.resolveAlias(TypeAliasRegistry.java:110)
    ... 98 more

大致的意思就是无法找到返回值对应的result类型:
我的错误代码如下:

<select id="getPageCount" resultMap="java.lang.Integer">
        select
        count(*)
        from policy_change_record
    </select>

可以看出,我返回的值只是一个Integer,不是一个resultMap,resultMap适合MyBatis的resultMap相对应着的:

<resultMap id="BaseResultMap" type="dbquery.core.bean.OnsPolicayChangeRecord">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="policy_id" property="policyId" jdbcType="BIGINT"/>
        <result column="policy_type" property="policyType" jdbcType="VARCHAR"/>
        <result column="provider_name" property="providerName" jdbcType="VARCHAR"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="failure_times" property="failureTimes" jdbcType="INTEGER"/>
        <result column="created_time" property="createdTime" jdbcType="VARCHAR"/>
        <result column="updated_time" property="updatedTime" jdbcType="VARCHAR"/>
        <result column="operate_type" property="operateType" jdbcType="VARCHAR"/>
        <result column="policy_content" property="policyContent" jdbcType="VARCHAR"/>
        <result column="operate_time" property="operateTime" jdbcType="VARCHAR"/>
    </resultMap>

因此如果返回的值是一个基本的数据类型使用的是resultType 如果是和resultMap
匹配的,比如说是集合,map等则使用resultMap,例如:

 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List"/>
        from policy_change_record
        where id = #{id,jdbcType=BIGINT}
    </select>

你可能感兴趣的:(error,mybatis,BaseResult)