Namespaces were optional in previous versions of MyBatis, which was confusing and unhelpful. Namespaces are now required and have a purpose beyond simply isolating statements with longer, fully-qualified names.

Namespaces enable the interface bindings as you see here, and even if you don’t think you’ll use them today, you should follow these practices laid out here in case you change your mind. Using the namespace once, and putting it in a proper Java package namespace will clean up your code and improve the usability of MyBatis in the long term.

Retrieved from

There are some elements that can benefit from namespace:

  • select element in mapper XML
  • insert element in mapper XML
  • update element in mapper XML
  • delete element in mapper XML
  • resultMap element in mapper XML
  • parameterMap element in mapper XML
  • sql element in mapper XML
  • @Results element in annotation


The plugin provides auto-completion for namespace elements wherever it can be referenced, for instance, you can reference a sql element in include element in mapper XML.

The lookup-strings for namespace elements contains two categories:

  • A namespace element that has the same namespace as the element you're editing
  • A namespace element that does not have the same namespace as the element you're editing

The plugin provides a simple class name in lookup-strings for the former, and the element id for the latter. Elements that can't be applied to current context are filtered out. And of course, navigation, refactoring and inspections are always available.


As you can see here that the qualified class name is used when you select a simple class name in the lookup-strings, and then namespace elements in that class namespace are provided for further auto-completion.


You can always reference namespace elements defined in mapper XML from annotations. But you can't do this from the opposite direction.

Mybatis generates an id for @Results element in annotation if the id value is absent, the plugin takes care of this as well.


Note: Currently, the plugin can't detect namespace elements if the namespace does not correspond to Java interface or class. This behavior will be improved in further release.

Codes Magic © 2013-2019 · Terms