输出参数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. 【u201】矩形覆盖

    Time Limit: 1 second Memory Limit: 128 MB [问题描述] 有N个矩形,矩形的底边边长为1,且均在X轴上,高度给出,第i个矩形的高为h[i],例如h = [3, ...

  2. echarts拓扑图(graph,力导向布局图)

    echarts连接:https://gallery.echartsjs.com/editor.html?c=xCLEj67T3H 讲解:https://www.cnblogs.com/koala201 ...

  3. deep Q learning小笔记

    1.loss 是什么 2. Q-Table的更新问题变成一个函数拟合问题,相近的状态得到相近的输出动作.如下式,通过更新参数 θθ 使Q函数逼近最优Q值 深度神经网络可以自动提取复杂特征,因此,面对高 ...

  4. ABP-AsyncLocal的使用

    1.与AsyncLocal对应的是ThreadLocal 2.两种类型 初始赋值 AsyncLocalString.Value = new List { "1" }; AsyncL ...

  5. echarts实现group关系图案例

    官网案例:https://www.echartsjs.com/examples/zh/editor.html?c=graph-simple 自己在项目中实现了两个group图: 1.先看实现效果,两个 ...

  6. IDEA模板快捷键

    2.1 psvm:可生成 main 方法 2.2 sout:System.out.println() 快捷输出 类似的: soutp=System.out.println("方法形参名 = ...

  7. Mybatis是如何实现SQL防注入的

    Mybatis这个框架在日常开发中用的很多,比如面试中经常有一个问题:$和#的区别,它们的区别是使用#可以防止SQL注入,今天就来看一下它是如何实现SQL注入的. 什么是SQL注入 在讨论怎么实现之前 ...

  8. jupyter启动后,浏览器自动打开,但是显示空白

    解决办法 1.在Windows菜单中,搜索regedit,打开它.2.导航到计算机> HKEY_CLASSES_ROOT> .js> Content Type(如果没找到需要新建或直 ...

  9. cannot open git-upload-pack,cannot open git-receive-pack,Can't connect to any URI错误解决方法eclipse

    cannot open git-upload-pack,cannot open git-receive-pack,Can't connect to any URI错误解决方法eclipse 解决ecl ...

  10. [转]numpy.random.randn()用法

    在python数据分析的学习和应用过程中,经常需要用到numpy的随机函数,由于随机函数random的功能比较多,经常会混淆或记不住,下面我们一起来汇总学习下. import numpy as np ...