Mybatis namespace?

탱귤생귤·2023년 10월 17일

Spring

목록 보기
9/14

namespace가 뭔지 헷갈려서 찾아보니 공식 문서에서 나온다.

이걸 적어주면 인터페이스를 실행시켜주는 것 같다. 되도록이면 Fully qualified names로 하는 것이 좋다고 한다.

https://mybatis.org/mybatis-3/getting-started.html#exploring-mapped-sql-statements

NOTE A note about namespaces.

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.

Name Resolution: To reduce the amount of typing, MyBatis uses the following name resolution rules for all named configuration elements, including statements, result maps, caches, etc.

Fully qualified names (e.g. “com.mypackage.MyMapper.selectAllThings”) are looked up directly and used if found.
Short names (e.g. “selectAllThings”) can be used to reference any unambiguous entry. However if there are two or more (e.g. “com.foo.selectAllThings and com.bar.selectAllThings”), then you will receive an error reporting that the short name is ambiguous and therefore must be fully qualified.

0개의 댓글