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

来源:互联网 发布:出题软件手机版 编辑:程序博客网 时间:2024/05/22 12:07

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语句执行

特殊sql语句包括:ddl语句、set等等特殊语句,都可以在update标签内执行;