In MyBatis Mapper XML Although there is code on the net that references a constant (static final), I didn't see much code that references enums, so I wrote it.
build.gradle
compile 'org.mybatis:mybatis:3.5.2'
SampleEnums.java
package com.example;
public class SampleEnums {
public enum Color {
RED("1"), GREEN("2"), BLUE("3");
private final String code;
private Color(final String code) {
this.code = code;
}
public String getCode() {
return this.code;
}
}
}
<select id="findByColorIsBlue" resultType="SampleDto">
SELECT *
FROM SAMPLE_TABLE
WHERE COLOR = '${@[email protected]}'
<!--Generated SQL
SELECT *
FROM SAMPLE_TABLE
WHERE COLOR = '2'
-->
</select>
<select id="findByColorIsBlue" resultType="SampleDto">
SELECT *
FROM SAMPLE_TABLE
WHERE COLOR = '${@com.example.SampleEnums$Color@BLUE}'
<!--Generated SQL
SELECT *
FROM SAMPLE_TABLE
WHERE COLOR = 'BLUE'
-->
</select>
Recommended Posts