手记

#1.获取表结构语句,批量更新表结构信息

JDBC元数据操作,DatabaseMetaData接口详解链接描述
MySQL中表的字段信息查询–information_schema.COLUMNS-- 链接描述

    <!--查询表结构信息-->
    <select id="selectDimTabCols" parameterType="java.lang.String" resultType="com.table.column.pojo.DimTabCols">

        select
			<!--column_name结构名,colName属性名:字段名-->
            column_name as colName,
			<!--字段描述描述-->
            column_comment as colDesc,
			<!--字段类型-->
            data_type as typeName,
			<!--字段长度-->
            character_maximum_length as colLength,
			<!--精度-->
            numeric_precision as colPrecision,
			<!--可否为空-->
            is_nullable as colNullable,
			<!--索引类型-->
            column_key as keyFlag,
			<!--列顺序-->
            ordinal_position as colSeq

        from information_schema.columns

        where table_name = #{tabName}

    <!--批量更新表字段登记信息-->
   </select>
   <update id="updateTabCols">
      update dim_tab_cols set col_name =
      <foreach collection='tabColsList' item='item' index='index' separator=' ' open='case col_Id' close='end'>
          when #{item.colId} then #{item.colName}
      </foreach>
      where col_id in
      <foreach  collection='colIds' item='item' index='index' separator=',' open='(' close=')'>
         #{item}
      </foreach>
   </update>
//索引类型设置,未验证
for (int i = 0; i < tabColsList.size(); i++) {
      if("NO".equals(tabColsList.get(i).getColNullable())){
createdColList.get(i).setIsNullable("0");
      }else {
createdColList.get(i).setIsNullable("1");
	  if(null == tabColsList.get(i).getKeyFlag()){
createdColList.get(i).setColumnKey("0");
//createdColList.get(i).setColIndexFlag("n");
      }else if("PRI".equals(tabColsList.get(i).getKeyFlag())){
createdColList.get(i).setColumnKey("1");
	  }else {
createdColList.get(i).setColumnKey("0");
//createdColList.get(i).setColIndexFlag("y");
            }
}*/
}
0人推荐
随时随地看视频
慕课网APP