You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Liquibase的INSERT语句中优雅使用Spring Boot配置参数?

Liquibase参数在SQL变更集的简洁引用方案

以下是几种无需substring去除引号的简洁解决方法:

1. 通过XML变更集指定参数类型

在XML格式的变更文件中,用<property>标签明确参数类型并关闭自动引号:

<property name="val1" value="${val1}" type="string" quoted="false"/>

之后在SQL语句里直接使用:

insert into table1 (name, value) values ('nameOfValue', ${val1});

2. 纯SQL文件使用Liquibase SQL标签包裹

将SQL语句放在<sql>标签内,确保参数解析正常:

<sql stripComments="true">
    insert into table1 (name, value) values ('nameOfValue', ${val1});
</sql>

3. 直接在SQL中用引号包裹参数

如果参数是字符串类型,直接在SQL层面给参数加单引号,无需额外处理:

insert into table1 (name, value) values ('nameOfValue', '${val1}');

若此写法之前无效,检查Spring Boot配置中是否自定义了spring.liquibase.parameter-prefix,确保参数能被Liquibase正确识别。

内容的提问来源于stack exchange,提问作者Greg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 09:01:02