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 http://www.mybatis.org/mybatis-3/getting-started.html
There are some elements that can benefit from namespace:
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:
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-2018 · Terms