application.properties中配置

mybatis.configuration.variables.k1='v1'
mybatis.configuration.variables.k2='v2'

XXXMapper.xml中使用

<select id="test1" resultMap="BaseResultMap" parameterType="java.util.Map">
        <choose>
            <when test="${k1}=='v1'">
                select * from SYS_USER
            </when>
            <otherwise>
                select * from SYS_USER where uname=${k1}
            </otherwise>
        </choose>
    </select>

测试1

mybatis.configuration.variables.k1='v1'

Springboot Mybatis 全局变量使用_java

 测试2

mybatis.configuration.variables.k1='v3'

Springboot Mybatis 全局变量使用_mybatis_02