Besides the Tomer answer, which works fine, you can also compare enum values using OGNL notation.
(Comparing enumeration values directly has the advantage of compiling, i.e. if you change the members of an enumeration, the query will work quickly.)
If the test enumeration lives in full.package.name as an open class Test.java, then in mapper.xml you will have:
<when test='t == @ full.package.name.Test@A '>
If the test enum is inside another class, for example:
package full.package.name; public class ExampleClass { public enum Test { A, B } }
Then in the mapper.xml file you will have:
<when test='t == @ full.package.name.ExampleClass$Test@A '>
The $ sign is not documented in the OGNL spec, I found it on the MyBatis problems page
PS: Old versions of MyBatis (e.g. 3.2.3) show ugly errors if the OGNL string is incorrect (e.g. NullPointerException). Newer versions show a more understandable error.
Vlad Dinulescu
source share