输出参数ResultType
1、输出参数为简单类型(8个基本+String)
2、输出参数为对象类型
3、输出参数为实体对象类型的集合:虽然输出类型为集合,但是resultType依然写集合的元素类型,eg:resultType="person"
4、输出参数类型为HashMap          --->一个HashMap对应一个人的多个元素(多个属性);查询所有人的属性:List<HashMap<String, Object>>
 
resultType和resultMap的区别:
resultType:实体类的属性、数据表的字段:类型、名字相同时
resultMap:实体类的属性、数据表的字段:类型、名字不同时
注意:当属性名和字段名不一致时,除了使用resultMap外还可以使用resultType+HashMap
resultType+HashMap方法:select 表的字段名 “类的属性名” from 
eg:<select id="queryPersonOutByHashMap" resultType="HashMap">
      select id "pid",name "pname" from person where id=1
   </select>
 
动语态sql:
动态查询
<select id="queryPersonbyNameorAgeWithSqlTag" parameterType="Person" resultType="Person">
        select id,name,age from person
        <where> <!-- <where>只能解决第一个<if>里面的and -->
            <if test="name!=null and name!=''">
                and name=#{name}        
            </if>
            <if test="age!=null and age!=0">
                and age=#{age}
            </if>
        </where>
    </select>
foreach:
<foreach>迭代的类型:数组、对象数组、集合、属性
查询语句:select * from person WHERE id in(1,2,3);
<!-- foreach查询   #{id}填补item separator指定分隔符-->
    <select id="queryPersonsbyIds" parameterType="grade" resultType="Person">
        select * from person
        <where>
            <if test="ids!=null and ids.size>0">
                <foreach collection="ids" open="id in (" close=")"
                item="id" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>
简单类型的array数组:
无论传递什么参数名,都用array代替。
<!-- 将多个元素放到数组里进行查询  必须是array代替数组-->
<select id="queryPersonsWithArray" parameterType="int[]" resultType="Person">
        select * from person
        <where>
            <if test="array!=null and array.length>0">
                <foreach collection="array" open="id in (" close=")"
                item="id" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>
list集合:
无论传递什么参数名,都用list代替。
<!-- 将多个元素放到list集合进行查询  必须是list-->
    <select id="queryPersonsWithList" parameterType="list" resultType="Person">
        select * from person
        <where>
            <if test="list!=null and list.size>0">
                <foreach collection="list" open="id in (" close=")"
                item="id" separator=",">
                    #{id}
                </foreach>
            </if>
        </where>
    </select>
对象数组:
<!-- 将多个元素放到对象数组里进行查询 ,必须是array ,parameterType="Object[]"-->
    <select id="queryPersonsWithObjectArray" parameterType="Object[]" resultType="Person">
        select * from person
        <where>
            <if test="array!=null and array.length>0">
                <foreach collection="array" open="id in (" close=")"
                item="person" separator=",">
                    #{person.id}
                </foreach>
            </if>
        </where>
    </select>
 
SQL片段:
    将相似功能代码提取出来,再进行引用。
步骤1、将代码提取出来;
<sql id="ObjectArrayIds">
    代码片段
</sql>
步骤2、用到时用id引用。
<include refid="ObjectArrayIds"></include>
注意:sql片段与引用处不在一个文件里的话refid前面加上namespace的值。

MyBatis3——输出参数ResultType、动语态sql的更多相关文章

  1. sql server使用sp_executesql返回拼接字符串里面的输出参数

    问题: 今天一同事请教博主,他拼接了一个语句,select表格形式数据,然后使用@@rowcount获取到行数. 但他又有这样特别的需求:想只获取行数而不返回表格数据结果,因为是while循环,不想返 ...

  2. mybatis入门系列二之输入与输出参数

    mybatis入门系列二之详解输入与输出参数   基础知识   mybatis规定mapp.xml中每一个SQL语句形式上只能有一个@parameterType和一个@resultType 1. 返回 ...

  3. 动态SQL的执行,注:exec sp_executesql 其实可以实现参数查询和输出参数的

    本文转自:http://www.cnblogs.com/hnsdwhl/archive/2011/07/23/2114730.html 当需要根据外部输入的参数来决定要执行的SQL语句时,常常需要动态 ...

  4. Oracle中使用PL/SQL如何定义参数、参数赋值、输出参数和 if 判断

    1.pl/sql如何定义参数 declare --1)定义参数 -- ban_Id number; ban_Name ); 2.pl/sql如何参数赋值 --2)参数赋值-- ban_Id :; ba ...

  5. sql server 带输入输出参数的分页存储过程(效率最高)

    create procedure proc_page_withtopmax( @pageIndex int,--页索引 @pageSize int,--每页显示数 @pageCount int out ...

  6. sql 存储过程 输出参数 输入参数

    1.简单的存储过程 create procedure porc_name as select * from 表 go 调用时: exec proc_name 2. 带参数的存储过程 create pr ...

  7. JavaWeb_(Mybatis框架)输入和输出参数_五

    系列博文: JavaWeb_(Mybatis框架)JDBC操作数据库和Mybatis框架操作数据库区别_一 传送门 JavaWeb_(Mybatis框架)使用Mybatis对表进行增.删.改.查操作_ ...

  8. MyBatis - 输入和输出参数

    基础知识 mybatis规定mapp.xml中每一个SQL语句形式上只能有一个@parameterType和一个@resultType 1. 返回值是一个对象的集合,@resultType中只能写该对 ...

  9. MySql.Data.dll 不支持输出参数

    insert INTO stu(name) VALUES('maimai'); set @ReturnValue=@@IDENTITY; string sql="insert INTO st ...

随机推荐

  1. JQuery多个异步操作后执行(resolve,promise,when,done)

    代码分享: //3秒后完成 function asyncThing1() { var dfd = $.Deferred(); setTimeout(function () { alert('async ...

  2. boostrap-非常好用但是容易让人忽略的地方【6】:role属性

    普通样式,鼠标hover没有任何效果 <span>content</span> 加上role属性的样式,鼠标hover会有cursor:pointer的效果 <span ...

  3. Struts2 类型转换(易百教程)

    在HTTP请求中的一切都被视为一个String由协议.这包括数字,布尔值,整数,日期,小数和一切.每一件事情是一个字符串,将根据HTTP.然而,Struts类可以有任何数据类型的属性.Struts的自 ...

  4. WebGPU学习(十一):学习两个优化:“reuse render command buffer”和“dynamic uniform buffer offset”

    大家好,本文介绍了"reuse render command buffer"和"dynamic uniform buffer offset"这两个优化,以及Ch ...

  5. AI炼丹 - 深度学习必备库 numpy

    目录 深度学习必备库 - Numpy 1. 基础数据结构ndarray数组 1.1 为什么引入ndarray数组 1.2 如何创建ndarray数组 1.3 ndarray 数组的基本运算 1.4 n ...

  6. 关于Qt中窗口的坐标

    主要是给自己以后参考,所以不会太仔细的讲解. #include "mainwindow.h" #include <QApplication> #include<Q ...

  7. java_回文检测

    package bao; import java.util.Scanner; public class Work { public static boolean digui(String str1,i ...

  8. Hyperledger Fabric动态配置Raft节点

    Hyperledger Fabric动态配置Raft节点 最近看官方文档发现新的共识算法etcdRaft允许动态添加或删除排序节点,所以也花了一天时间操作了以下,写篇文章把整个过程记录一下. 初始网络 ...

  9. 洛谷p1345---最小割的奇妙运用

    让你去掉最少的点,使得c1和c2变得不连通,你有办法吗??? 这是最小割呀!!! 网络流的最小割去掉的是边,构造边的顶点的唯一关系就好了!!! 需要注意一点 #include<iostream& ...

  10. react项目使用antd

    在开始实践之前要确保搭建React单页面开发环境,如果还没有搭建好开发环境的朋友请移步到如何搭建React单页面开发环境. 首先在命令行模式下创建一个React项目(项目名使用小写字母命名):(win ...