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:

  1. /my_application
  2. /bin
  3. /devlib
  4. /lib <-- MyBatis *.jar files go here.
  5. /src
  6. /org/myapp/
  7. /action
  8. /data <-- MyBatis artifacts go here, including, Mapper Classes, XML Configuration, XML Mapping Files.
  9. /mybatis-config.xml
  10. /BlogMapper.java
  11. /BlogMapper.xml
  12. /model
  13. /service
  14. /view
  15. /properties <-- Properties included in your XML Configuration go here.
  16. /test
  17. /org/myapp/
  18. /action
  19. /data
  20. /model
  21. /service
  22. /view
  23. /properties
  24. /web
  25. /WEB-INF
  26. /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.