mybatis.configuration.variables是一个可自定义的全局变量:
在 application.yml 中定义:
mybatis:
mapper-locations: classpath:mapper/*.xml
type-aliases-package: com.example.entity
configuration:
variables:
dbtype: mysql
mapper.xml中的使用:
<!-- 更新子树 -->
<update id="updateSunTreeParentIds">
update sys_menu set parent_ids= CONCAT(#{newParentIds},
<if test="'${dbType}' == 'mysql'">
substring(parent_ids, length(#{oldParentIds})+1,length(parent_ids)+1))
</if>
<if test="'${dbType}' == 'oracle'">
substr(parent_ids, length(#{oldParentIds})+1,length(parent_ids)+1))
</if>
where parent_ids like concat(#{oldParentIds}, '%')
</update>
需要加引号,数字类型的可以不用管, 但如果遇到属性值为中文,不加引号报错提示列找不到,这个问题不难理解, 弄明白了mybatis的#和$的区别就明白了。
- mybatis configuration 全局 变量 variablesmybatis configuration全局 变量 condition_variable变量condition variable 层级 变量variables框架 变量variables工资 因素 del_delete_variable变量variable delete 变量 函数variables functions 变量httprunner variables 变量unresolved webstorm variable 线性 变量regression variable configuration组件 核心mybatis