Mybatis中的resultType和resultMap(mybatis执行ddl语句和特殊sql语句)

Mybatis中的resultType和resultMap

mybatis的resultType的类型不能添加为java.util.List,在不知道具体怎么映射的情况下可以写为java.util.Map,例如:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="edu.hrbeu.platform.modeling.table.dao.TableMapper">
    <!-- 查看表是否存在 -->
    <select id="existTable" resultType="Integer">
        SELECT count(TABLE_NAME) 
        FROM 
        INFORMATION_SCHEMA.TABLES 
        where 
        TABLE_SCHEMA = #{databaseName, jdbcType=VARCHAR}
        AND
        TABLE_NAME=#{tableName, jdbcType=VARCHAR}
    </select>
    <!-- 获取当前表的创建表语句和表名称 -->
    <select id="showCretaTable" resultType="java.util.Map" parameterType="java.lang.String">
        show create table ${value}
    </select>

    <!-- 删除表 update -->
    <update id="dropTable" parameterType="java.lang.String">
        drop table IF EXISTS ${value}
    </update>
    <!--创建表 update -->
    <update id="createNewTable" parameterType="java.lang.String">
        ${value}
    </update>
</mapper>

获取创建表sql语句的java代码:

@Test
    public void showCretaTable() throws Exception {
        Map showCretaTable = tableMapper.showCretaTable("certif");
        System.out.println("表名:" + showCretaTable.get("Table"));
        System.out.println("创表语句:" + showCretaTable.get("Create Table"));
    }

你可能感兴趣的:(sql,mybatis)