日常报错记录2: MyBatis:DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.------------ Cause: java.lang.NoSuchMethodException: com.offcn.dao.ShopDao.<init>()

 

 直接上干货:

 报错归纳 1:

 DEBUG [main] - Logging initialized using 'class org.apache.ibatis.logging.slf4j.Slf4jImpl' adapter.

原因:xml 里面不能有 java 方不存在的类,它是会去找的,找不到就报错,所以,万一删掉 java 类了,xml 里面的相对应映射的字段也要注释掉。遇到两次了!浪费不少时间!

 

2.MyBatis     他要加空构造   实例化对象

原因:MyBitis ,他实体类 pojo  class 里 要加空构造

 

 

 

3. 写法

 

 

 class 是点,路径是斜杠

 

 

 

 

4.

xml 控制多级级联查数据库,是可以的,(MyBatis xml 作为实现 数据库查询),我这里四级连着查询

 

<?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.XXXX.dao.ShopDao">

<!--private int sid;

private String sname;

private List</span><span style="color: rgba(128, 128, 128, 1)">&lt;</span>Book<span style="color: rgba(128, 128, 128, 1)">&gt;</span> blist;<span style="color: rgba(0, 128, 128, 1)">--</span><span style="color: rgba(0, 128, 128, 1)">&gt;</span>

<resultMap id="resultMap_shop" type="shop">

<span style="color: rgba(128, 128, 128, 1)">&lt;</span>id property<span style="color: rgba(128, 128, 128, 1)">=</span>"sid" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"sid"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>id<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
<span style="color: rgba(128, 128, 128, 1)">&lt;</span>result property<span style="color: rgba(128, 128, 128, 1)">=</span>"sname" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"sname" <span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>result<span style="color: rgba(128, 128, 128, 1)">&gt;</span>

<span style="color: rgba(128, 128, 128, 1)">&lt;</span>collection property<span style="color: rgba(128, 128, 128, 1)">=</span>"blist"  ofType<span style="color: rgba(128, 128, 128, 1)">=</span>"book"<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
    <span style="color: rgba(128, 128, 128, 1)">&lt;</span>id property<span style="color: rgba(128, 128, 128, 1)">=</span>"bid" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"bid"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>id<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
    <span style="color: rgba(128, 128, 128, 1)">&lt;</span>result property<span style="color: rgba(128, 128, 128, 1)">=</span>"bname" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"bname"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>result<span style="color: rgba(128, 128, 128, 1)">&gt;</span>

        <span style="color: rgba(128, 128, 128, 1)">&lt;</span>association property<span style="color: rgba(128, 128, 128, 1)">=</span>"<span style="color: rgba(255, 0, 255, 1)">user</span>" javaType<span style="color: rgba(128, 128, 128, 1)">=</span>"<span style="color: rgba(255, 0, 255, 1)">user</span>"<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
            <span style="color: rgba(128, 128, 128, 1)">&lt;</span>id property<span style="color: rgba(128, 128, 128, 1)">=</span>"uid" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"uid"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>id<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
            <span style="color: rgba(128, 128, 128, 1)">&lt;</span>result property<span style="color: rgba(128, 128, 128, 1)">=</span>"uname" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"uname"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>result<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
            <span style="color: rgba(128, 128, 128, 1)">&lt;</span>result property<span style="color: rgba(128, 128, 128, 1)">=</span>"password" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"password"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>result<span style="color: rgba(128, 128, 128, 1)">&gt;</span>

            <span style="color: rgba(128, 128, 128, 1)">&lt;</span>association property<span style="color: rgba(128, 128, 128, 1)">=</span>"p" javaType<span style="color: rgba(128, 128, 128, 1)">=</span>"person" <span style="color: rgba(128, 128, 128, 1)">&gt;</span>
                <span style="color: rgba(128, 128, 128, 1)">&lt;</span>id property<span style="color: rgba(128, 128, 128, 1)">=</span>"pid" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"pid"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>id<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
                <span style="color: rgba(128, 128, 128, 1)">&lt;</span>result property<span style="color: rgba(128, 128, 128, 1)">=</span>"pname" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"pname"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>result<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
                <span style="color: rgba(128, 128, 128, 1)">&lt;</span>result property<span style="color: rgba(128, 128, 128, 1)">=</span>"sex" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"sex"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>result<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
                <span style="color: rgba(128, 128, 128, 1)">&lt;</span>result property<span style="color: rgba(128, 128, 128, 1)">=</span>"birthday" <span style="color: rgba(0, 0, 255, 1)">column</span><span style="color: rgba(128, 128, 128, 1)">=</span>"birthday"<span style="color: rgba(128, 128, 128, 1)">&gt;&lt;/</span>result<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
            <span style="color: rgba(128, 128, 128, 1)">&lt;/</span>association<span style="color: rgba(128, 128, 128, 1)">&gt;</span>

        <span style="color: rgba(128, 128, 128, 1)">&lt;/</span>association<span style="color: rgba(128, 128, 128, 1)">&gt;</span>

<span style="color: rgba(128, 128, 128, 1)">&lt;/</span>collection<span style="color: rgba(128, 128, 128, 1)">&gt;</span>

<!-- <association property="blist" javaType=""-->
</resultMap>

<!-- List<Shop> getAll(int sid);-->

<span style="color: rgba(128, 128, 128, 1)">&lt;</span><span style="color: rgba(0, 0, 255, 1)">select</span> id<span style="color: rgba(128, 128, 128, 1)">=</span>"getAll" parameterType<span style="color: rgba(128, 128, 128, 1)">=</span>"<span style="color: rgba(0, 0, 255, 1)">int</span>" resultMap<span style="color: rgba(128, 128, 128, 1)">=</span>"resultMap_shop"<span style="color: rgba(128, 128, 128, 1)">&gt;</span>
  <span style="color: rgba(0, 0, 255, 1)">select</span> <span style="color: rgba(0, 0, 255, 1)">from</span> t_shop s,t_book b,t_user u,t_person p <span style="color: rgba(0, 0, 255, 1)">where</span> u.user_person_fk<span style="color: rgba(128, 128, 128, 1)">=</span>p.pid <span style="color: rgba(128, 128, 128, 1)">and</span> b.book_user_fk<span style="color: rgba(128, 128, 128, 1)">=</span>u.uid <span style="color: rgba(128, 128, 128, 1)">and</span> s.sid<span style="color: rgba(128, 128, 128, 1)">=</span><span style="color: rgba(0, 0, 0, 1)">#{sid}

</span><span style="color: rgba(128, 128, 128, 1)">&lt;/</span><span style="color: rgba(0, 0, 255, 1)">select</span><span style="color: rgba(128, 128, 128, 1)">&gt;</span>

</mapper>

 

5.

Cause: java.lang.NoSuchMethodException: com.offcn.dao.ShopDao.<init>(),其实是缺少构造,但构造没问题,之后发现是这个写错