Springboot Mybatis 全局变量使用

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'

 测试2

mybatis.configuration.variables.k1='v3'

 

posted @ 2023-06-08 09:57  天天代码码天天  阅读(182)  评论(0编辑  收藏  举报  来源