1. 程式人生 > >mybatis 報錯There is no getter for property named 'XXX' in 'class com.xx.xx'

mybatis 報錯There is no getter for property named 'XXX' in 'class com.xx.xx'

mybatis報錯資訊記錄:

### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'batchDetails' in 'class com.mybatis.model.Batch'

### Error querying database.  Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'batchDetails' in 'class com.mybatis.model.Batch'

這個問題會氣死人,單詞寫錯了

      <collection property="batchList" ofType="com.mybatis.model.Batch">
            <id column="batch_id" property="batch_id"/>
            <result column="cus_id" property="cus_id"/>
            <result column="number" property="number"/>
            <result column="createtime" property="createtime" javaType="java.util.Date"/>
            <result column="note" property="note"/>
            <!--訂單(批次)明細-->
            <collection property="batchDetails" ofType="com.mybatis.model.BatchDetail">
                <id column="id" property="id"/>
                <result column="batch_id" property="batch_id"/>
                <result property="product_id" column="product_id"/>
                <result property="product_num" column="product_num"/>
                <!--每個明細對應單獨(一對一)的說明-->
                <association property="finacialProduct" javaType="com.mybatis.model.FinacialProduct">
                    <id column="product_id" property="id"/>
                    <result column="name" property="name"/>
                    <result column="price" property="price"/>
                    <result column="detail" property="detail"/>
                </association>
            </collection>
        </collection>

其中第八行的<collection property="batchDetails",要對應第一行的ofType="com.mybatis.model.Batch">

Bath.java中的欄位

public class Batch {
    private int batch_id;
    private int cus_id;
    private String number;
    private Date createtime;
    private String note;
    private List<BatchDetail> batchDetials;
}

這邊寫的是batchDetials

batchDetials和batchDetails

 

此類報錯和描述的一樣,就是找不到,可以全域性搜尋找一下報錯的欄位等方法來測試