Mybatis的动态创建删除表
生活随笔
收集整理的這篇文章主要介紹了
Mybatis的动态创建删除表
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Mybatis中可以使用JSTL標簽
動態刪除表
Mapper
void deleteTable(@Param("tableName") String tableName);Mapper.xml
<update id="deleteTable">DROP TABLE ${tableName} </update>動態創建表
Mapper
void createTable(@Param("newTableName") String newTableName, @Param("columns") List<Map<String, String>> columns);Mapper.xml
<update id="createTable">CREATE TABLE ${newTableName} ("ID" VARCHAR2(64 BYTE) PRIMARY KEY NOT NULL,<foreach item="item" index="index" collection="columns" open="" separator="," close=",">"${item.code}"<choose><when test="item.type=='STRING'">VARCHAR2(${item.length} BYTE) NULL</when><when test="item.type=='NUMBER'">NUMBER(${item.length},${column.precision}) NULL</when><otherwise>TIMESTAMP(${item.length}) NULL</otherwise></choose></foreach>"CREATE_TIME" TIMESTAMP(6) NULL ,"MODIFY_TIME" TIMESTAMP(6) NULL) </update>或者
Mapper
void createTableColumn(@Param("newTableName") String newTableName, @Param("column") Map<String, String> column);Mapper.xml
<update id="createTableColumn" parameterType="java.util.Map">CREATE TABLE ${newTableName} ("ID" VARCHAR2(64 BYTE) PRIMARY KEY NOT NULL,"CREATE_TIME" TIMESTAMP(6) NULL ,"MODIFY_TIME" TIMESTAMP(6) NULL ,"${column.code}"<choose><when test="column.type=='STRING'">VARCHAR2(${column.length} BYTE) NULL</when><when test="column.type=='NUMBER'">NUMBER(${column.length},${column.precision}) NULL</when><otherwise>TIMESTAMP(${column.length}) NULL</otherwise></choose>) </update>總結
以上是生活随笔為你收集整理的Mybatis的动态创建删除表的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Mybatis的动态查询
- 下一篇: Mybatis动态的添加删除列