有一個需求要獲取 mysql的建表語句,代碼很簡單,直接在xml中寫
show create table ${庫名}.${表名}
這樣就獲取到了建表語句。
完整的代碼如下,
<select id="getDDLTable" resultType="java.util.Map"> show create table ${catalog}.${tableName} </select>
/** * 根據表名庫名查詢建表DDL語句 * @param catalog 庫名 * @param tableName 表名 * @return */ Map getDDLTable(@Param("catalog") String catalog, @Param("tableName") String tableName);
需要注意一點,xml中的取值,必須是 $ 符號,不能是 # 取值,否則會報