Closed1

【MyBatis】mapperファイルでJavaの定数を使用したい

やむやむ

bind要素か${}プレースホルダーを使用する

定数クラス
public class Constants {
    public static final String SOME_CONSTANT = "someValue";
}

bind要素を使用する方法

<select id="selectExample" resultType="map">
    <bind name="constantValue" value="@com.example.Constants@SOME_CONSTANT"/>
    SELECT * FROM some_table WHERE some_column = #{constantValue}
</select>

${}プレースホルダーを直接使用する方法

<select id="selectExample" resultType="map">
    SELECT * FROM some_table WHERE some_column = ${@com.example.Constants@SOME_CONSTANT}
</select>
このスクラップは2023/09/27にクローズされました