why Invalid bound statement

15 views
Skip to first unread message

刘志

unread,
Jun 14, 2024, 10:11:46 PM (12 days ago) Jun 14
to mybatis-user
mybatis version 3.5.16

There are three injection methods
<mappers>
        <mapper resource="com.tutorial.mybatis.mapper/BlogMapper.xml"/>
        <mapper resource="com.tutorial.mybatis.mapper/UserMapper.xml"/>
        <mapper resource="com.tutorial.mybatis.mapper/OrderMapper.xml"/>
        <mapper resource="com.tutorial.mybatis.mapper/BookMapper.xml"/>
        <mapper resource="com.tutorial.mybatis.mapper/AnimalMapper.xml"/>
        <mapper resource="com.tutorial.mybatis.mapper/FoodMapper.xml"/>
</mappers>

 <mappers>
        <mapper class="com.tutorial.mybatis.mapper.BlogMapper"/>
        <mapper class="com.tutorial.mybatis.mapper.UserMapper"/>
        <mapper class="com.tutorial.mybatis.mapper.OrderMapper"/>
        <mapper class="com.tutorial.mybatis.mapper.BookMapper"/>
        <mapper class="com.tutorial.mybatis.mapper.AnimalMapper"/>
        <mapper class="com.tutorial.mybatis.mapper.FoodMapper"/>
</mappers>

<mappers>
  <package name="com.tutorial.mybatis.mapper"/>
</mappers>

Only the resource method can take effect, the other two are invalid bindings
The directory structure is as follows src/main/java └── com └── tutorial └── mybatis └── mapper ├── FoodMapper.java ├── UserMapper.java src/main/resources └── com └── tutorial └── mybatis └── mapper ├── FoodMapper.xml ├── UserMapper.xml I don’t quite understand why this problem occurs. Please help me solve it as soon as possible.

Iwao AVE!

unread,
Jun 17, 2024, 12:09:13 PM (9 days ago) Jun 17
to mybati...@googlegroups.com

Hello,

If the directory structure is …

└── com
    └── tutorial
        └── mybatis
            └── mapper
                └── BlogMapper.xml

… the config should look as follows:

<mapper resource="com/tutorial/mybatis/mapper/BlogMapper.xml"/>

If MyBatis finds the XML mapper with the following config ….

<mapper resource="com.tutorial.mybatis.mapper/BlogMapper.xml"/>

… it means that the directory structure is wrong.

└── com.tutorial.mybatis.mapper
    └── BlogMapper.xml

And that is why specifying class or package does not work.

It is difficult to differentiate the directory structures in some IDEs.
Check it using the system’s file manager (e.g. Finder, Explorer).

Regards,
Iwao


--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/c8d1e6ff-093a-4071-a680-5362c3f6c562n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages