在MyBatis的select,insert,update,delete这些元素中都提到了parameterType这个属性。MyBatis现在使用parameterType有基本类型和JAVA复杂数据类型。

基本类型:包含int,String,Date等,基本数据类型作为传入参数,只能传入一个。通过#{参数名}即可获取传入的值

复杂类型:包含JAVA实体类,Map,通过#{属性名}或#{Map的keyName}即可获取传入的值。

1.基本类型参数示例

xml文件

<select id="selectName"   parameterType="int"   resultType="com.domain.Person">

    select * from tableName where id = #{id}

</select>

Java代码

List<Person> plist = Mapper.selectPerson();

for(Person persion:plist){

System.out.println(persion.toString());

}

.JAVA 实体类型参数示例

xml文件

<select id="selectName"   parameterType="com.domain.Person"   resultType="com.domain.Person">

    select * from tableName where id = #{id}

</select>

Java代码

Person person = new Person();

person.setId();

List<Person>  plist  =  Mapper.selectPerson(person)

for(Person person : plist){

System.out.println(person.toString());

}

.Map参数示例

xml文件

<select id="selectName"   parameterType="Map"   resultType="com.domain.Person">

    select * from tableName where id = #{id} and sex=#{sex}

</select>

Java代码

Map<String,String> map = new HasMap<String,String>();

map.put("id",);

map.put("sex","男");

List<Person> plist  = Mapper.selectPerson(map);

for(Person person:plist){

System.out.println(person.toString());

}

MyBatis 传入参数之parameterType的更多相关文章

  1. mybatis传入参数类型parameterType和输出结果类型resultType详解

    前言 Mybatis的Mapper文件中的select.insert.update.delete元素中都有一个parameterType和resultType属性,parameterType属性用于对 ...

  2. mybatis传入参数类型parameterType详解

    前言 Mybatis的Mapper文件中的select.insert.update.delete元素中都有一个parameterType属性,用于对应的mapper接口方法接受的参数类型. ( res ...

  3. MyBatis传入参数与parameterType

    参考:http://openwares.net/database/mybatis_parametertype.html Mybatis的Mapper文件中的select.insert.update.d ...

  4. MyBatis传入参数为list、数组、map写法

    1.foreach简单介绍: foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有item,index,collection,open,sep ...

  5. MyBatis传入参数为list、数组、map写法(转载)

    MyBatis传入参数为list.数组.map写法 1.foreach简单介绍: foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合. foreach元素的属性主要有item ...

  6. MyBatis传入参数

    在MyBatis的select.insert.update.delete这些元素中都提到了parameterType这个属性.MyBatis现在可以使用的parameterType有基本数据类型和Ja ...

  7. MyBatis传入参数为集合、数组SQL写法

    参考:http://blog.csdn.net/small____fish/article/details/8029030 foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合 ...

  8. MyBatis传入参数为集合 list 数组 map写法

    foreach的主要用在构建in条件中,它可以在SQL语句中进行迭代一个集合.foreach元素的属性主要有item,index,collection,open,separator,close.ite ...

  9. Mybatis传入参数类型为Map

    mybatis更新sql语句: <update id="publishT00_notice" parameterType="Map"> update ...

随机推荐

  1. 使用 HttpClient 请求 Web Api

    1.获取 post 请求 body 内容 [HttpPost] public string GetId() { //如果方法参数里面有 [FromBody],则需要重新调整内容指针,再进行读取. // ...

  2. Docker学习笔记 - Docker Compose

    一.概念 Docker Compose 用于定义运行使用多个容器的应用,可以一条命令启动应用(多个容器). 使用Docker Compose 的步骤: 定义容器 Dockerfile 定义应用的各个服 ...

  3. 为什么我不推荐你使用vue-cli创建脚手架?

    最近在知乎看到一个问题,原问题如下: "很奇怪,为什么现在能找到自己手动创建vue脚手架的文章非常少,而且大家似乎对webpack4的热情并不高,对于想基于vue2.0+webpack4搭建 ...

  4. leetcode算法: Average of Levels in Binary Tree

    Given a non-empty binary tree, return the average value of the nodes on each level in the form of an ...

  5. 初学Java Web(1)——Web概述

    已经很久没有更新博客了,过年忙着吃喝玩乐,就怠惰了一小下下?幸好这学期新开的课程都比较有趣--Java Web和Android.至少对于我自己来说,既充满挑战,又富有趣味. --[1.Web概述]-- ...

  6. linux远程传输

    scp scp 命令是 SSH中最方便有用的命令了,scp就是secure copy,是用来进行远程文件拷贝的.数据传输使用 ssh,并且和ssh 使用相同的认证方式,提供相同的安全保证. 与rcp ...

  7. [LeetCode] Longest Continuous Increasing Subsequence 最长连续递增序列

    Given an unsorted array of integers, find the length of longest continuous increasing subsequence. E ...

  8. localStorage学习总结

    一.本地存储 在HTML5诞生之前,网站如果想在浏览器端存储数据,只能使用Cookie,使用Cookie有较多的限制. Cookie问题: 1.cookie大小限制在4K左右(各个浏览器不一致) 2. ...

  9. [Codeforces 863B]Kayaking

    Description Vadim is really keen on travelling. Recently he heard about kayaking activity near his t ...

  10. [HNOI2008]神奇的国度

    题目描述 K国是一个热衷三角形的国度,连人的交往也只喜欢三角原则.他们认为三角关系:即AB相互认识,BC相互认识,CA相互认识,是简洁高效的.为了巩固三角关系,K国禁止四边关系,五边关系等等的存在. ...