我的项目是一个数据库中心,类似于 PLSQL,但在 Web 浏览器中使用。有时我需要创建或更改表,但我不知道Mybatis是否支持DDL,并且我没有找到任何关于这方面的文档。
最佳答案
大多数情况下,DDL 的工作方式与使用 mybatis 的 DML 类似。唯一的区别是您需要使用 ${} 而不是 #{} 作为参数。大多数数据库不支持使用 DDL 的预准备语句。 $ 符号是字符串替换,而不是准备好的语句的参数。
<update id="exchangePartition" parameterType="java.util.Map">
alter table ${destinationTableName}
exchange partition ${destinationPartitionName}
with table ${sourceTableName}
including indexes
with validation
</update>
了解调用语法以及可调用的语句类型来调用存储过程也很有帮助。
<update id="gatherStatistics" statementType="CALLABLE" parameterType="Map">
{call
dbms_stats.gather_table_stats(
ownname => #{tableOwner},
tabname => #{tableName}
<if test="partitionName != null">
, partname => #{partitionName}
</if>
)
}
</update>
关于mybatis - Mybatis支持DDL吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18786560/