MyBatis報錯找不到對應的JavaBean類


錯誤信息

org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/bucai/one_to_one/OneToOneMapper.xml
### The error occurred while processing mapper_resultMap[oneToOne]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'com/bucai/one_to_one/OneToOneMapper.xml'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'card'.  Cause: java.lang.ClassNotFoundException: Cannot find class: card

Mapper文件

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.bucai.table01.OneToOneMapper">
<!--    配置字段和實體對象屬性的映射關系-->
    <resultMap id="oneToOne" type="card">
        <id column="cid" property="id"/>
        <result column="number" property="number"/>
        <!--association:配置被包含對象的映射關系
        property:被包含對象的變量名
        Java type :被包含對象的數據類型-->
        <association property="p" javaType="person">
            <id column="pid" property="id"/>
            <result column="name" property="name"/>
            <result column="age" property="age"/>
        </association>
    </resultMap>
    <select id="selectAll" resultMap="oneToOne">
        SELECT c.id cid,number,pid,NAME,age FROM card c,person p WHERE c.pid=p.id
    </select>

</mapper>

解決方法:在type和JavaType后面寫上完整路徑

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM