Directory Structure
Before we dive in to the Java API itself, it’s important to understand the best practices surrounding directory structures. MyBatis is very flexible, and you can do almost anything with your files. But as with any framework, there’s a preferred way.
Let’s look at a typical application directory structure:
- /my_application
- /bin
- /devlib
- /lib
<-- MyBatis *.jar files go here.
- /src
- /org/myapp/
- /action
- /data
<-- MyBatis artifacts go here, including, Mapper Classes, XML Configuration, XML Mapping Files.
- /mybatis-config.xml
- /BlogMapper.java
- /BlogMapper.xml
- /model
- /service
- /view
- /properties
<-- Properties included in your XML Configuration go here.
- /test
- /org/myapp/
- /action
- /data
- /model
- /service
- /view
- /properties
- /web
- /WEB-INF
- /web.xml
Remember, these are preferences, not requirements, but others will thank you for using a common directory structure.
The rest of the examples in this section will assume you’re following this directory structure.