该参数只表示一个参数类型,但是如果有多个参数的话,就不要使用该参数了。一个参数的这种其实没有必要写parameterType,而且还有就是多个参数的时候也没有必要写parameterType,也就是说,其实该参数的存在是不是特别必要的。其中@Param和parameterType 二者存其一即可。看名字就能知道ParameterType是按照类型进行匹配,而@Param是按照名字进行匹配。

一.实体类型

1.都不包含
都不包含,则采用类型进行识别。

void mysave(Pac pac);
<insert id="mysave">insert into pac(productlevel,satelliteid) values (#{productLevel},#{satelliteID})//#{成员变量名}
</insert>

2.只含parameterType
只包含parameterType,则采用类型进行识别,并按照成员变量名称进行匹配

void mysave(Pac pac);
<insert id="mysave" parameterType="com.example.xmlsax_reader.entity.Pac">insert into pac(productlevel,satelliteid) values (#{productLevel},#{satelliteID})//#{成员变量名}
</insert>

3.只含@Param
只包含@Param,要通过参数名字进行访问才行。

void mysave(@Param("pac123") Pac pac);
<insert id="mysave">insert into pac(productlevel,satelliteid) values (#{pac123.productLevel},#{pac123.satelliteID})//#{名字.成员变量名}
</insert>

4.都包含
都包含,则默认按照名字进行匹配

void mysave(@Param("pac123") Pac pac);
<insert id="mysave" parameterType="com.example.xmlsax_reader.entity.Pac">insert into pac(productlevel,satelliteid) values (#{pac123.productLevel},#{pac123.satelliteID})//#{参数名.成员变量名}
</insert>

二.基本类型

1.只含parameterType
则只按照类型匹配,而不会考虑名字的匹配

Pac myselect(String productLevel);
///测试,不报错。void myselect(String productLevel);
<select id="myselect" parameterType="String" resultType="com.example.xmlsax_reader.entity.Pac">select * from pac where productlevel = #{i}
</select>  //#{任意字符}

2.只含有@Param
这种就会只按照名字匹配,而不是按照类型匹配了,如果名字不同,则会异常

 Pac myselect(@Param("param") String productLevel);
<select id="myselect" parameterType="String" resultType="com.example.xmlsax_reader.entity.Pac">select * from pac where productlevel = #{param}
</select> //   #{@Param中的参数名称}

3.都不包含
都不包含,则默认按照类型匹配,占位符和一个参数的入参相匹配。

 Pac myselect(String productLevel);
<select id="myselect" resultType="com.example.xmlsax_reader.entity.Pac">select * from pac where productlevel = #{param}</select>

4.都包含
都包含,则按照名字匹配,这个时候其实parameterType已经没有什么作用了

 Pac myselect(@Param("param") String productLevel);
<select id="myselect" parameterType="String" resultType="com.example.xmlsax_reader.entity.Pac">select * from pac where productlevel = #{param}
</select>

5.多个参数
对于多参数的,则就无法直接通过参数类型来识别了,而是必须要通过@Param来进行识别

Pac myselect(@Param("level") String productLevel,@Param("sate") String satelliteID);
<select id="myselect" resultType="com.example.xmlsax_reader.entity.Pac">select * from pac where productlevel = #{level} and satelliteid = #{sate}
</select>

三. Map类型

1.都不包含或只含parameterType
这种其实就是按照类型匹配,这个时候,对应的占位符采用的是只有key

void mapsave(Map<String,? extends Object> map);
<insert id="mapsave">insert into pac(productlevel,satelliteid) values (#{key1},#{key2})</insert>

2.只含@Param或者都包含
如果是注解,则是按照名字匹配。

 void mapsave(@Param("map") Map<String,? extends Object> map);
 <insert id="mapsave" parameterType="map">insert into pac(productlevel,satelliteid) values (#{map.key1},#{map.key2})</insert>

四.List类型

1.都不包含或只含parameterType
只包含parameterType,则按照类型来识别。

List<Pac> selectBylist(List<String> list);
 <select id="selectBylist" resultType="com.example.xmlsax_reader.entity.Pac">select * from pac where productlevel in<foreach collection="list" separator="," open="(" close=")" item="item">#{item}</foreach>
</select>

2.只含@Param或者都包含
如果是注解,则是按照名字匹配。

 List<Pac> selectBylist(@Param("param") List<String> list);
<select id="selectBylist"  resultType="com.example.xmlsax_reader.entity.Pac">select * from pac where productlevel in<foreach collection="param" separator="," open="(" close=")" item="item">#{item}</foreach>
</select>

resultType

别名 映射的类型
_byte byte
_long long
_short short
_int int
_integer int
_double double
_float float
_boolean boolean

string String
byte Byte
long Long
short Short
int Integer
integer Integer
double Double
float Float
boolean Boolean
date Date
decimal BigDecimal
bigdecimal BigDecimal
object Object

map Map
hashmap HashMap
list List
arraylist ArrayList
collection Collection
iterator Iterator

1.一般数据类型

    String getEmpNameById(Integer id);
    <!-- 指定 resultType 返回值类型时 String 类型的,string 在这里是一个别名,代表的是 java.lang.String 对于引用数据类型,都是将大写字母转小写,比如 HashMap 对应的别名是 'hashmap'基本数据类型考虑到重复的问题,会在其前面加上 '_',比如 byte 对应的别名是 '_byte'--><select id="getEmpNameById" resultType="string">select username from t_employee where id = #{id}</select>

2.JavaBean类型

    Employee getEmpById(Integer id);
    <!-- 通过 resultType 指定查询的结果是 Employee 类型的数据  只需要指定 resultType 的类型,MyBatis 会自动将查询的结果映射成 JavaBean 中的属性--><select id="getEmpById" resultType="com.example.xmlsax_reader.entity.Employee">select * from t_employee where id = #{id}</select>

3.返回list类型
有时候我们要查询的数据不止一条,比如:模糊查询,全表查询等,这时候返回的数据可能不止是一条数据,对于多数据的处理可以存放在List集合中。

    List<Employee> getAllEmps();
    <!--注意这里的 resultType 返回值类型是集合内存储数据的类型,不是 'list'--><select id="getAllEmps" resultType="com.example.xmlsax_reader.entity.Employee">select * from t_employee</select>

4、返回Map类型

  1. 如果查询的结果是一条,我们可以把查询的数据以{表字段名, 对应的值}方式存入到Map中。
    Map<String, Object> getEmpAsMapById(Integer id);
    <!-- 注意这里的 resultType 返回值类型是 'map'--><select id="getEmpAsMapById" resultType="map">select * from t_employee where id = #{id}</select>
  1. 如果查询的结果是多条数据,我们也可以把查询的数据以{表中某一字段名, JavaBean}方式来封装成Map。
    // @MapKey 中的值表示用数据库中的哪个字段名作 key@MapKey("id")Map<Integer, Employee> getAllEmpsAsMap();
    <!--注意 resultType 返回值类型,不再是 'map',而是 Map 的 value 对应的 JavaBean 类型--><select id="getAllEmpsAsMap" resultType="com.example.xmlsax_reader.entity.Employee">select * from t_employee</select>

parameterType 用法相关推荐

  1. 详谈parameterType与resultType的用法

    resultMap 表示查询结果集与java对象之间的一种关系,处理查询结果集,映射到java对象. resultMap 是一种"查询结果集---Bean对象"属性名称映射关系,使 ...

  2. parameterType的用法

    parameterType的用法-> 在mybatis映射接口的配置中,有select,insert,update,delete等元素都提到了 parameterType的用法,paramete ...

  3. Mybatis中parameterType的用法

    在mybatis映射接口的配置中,有select,insert,update,delete等元素都提到了parameterType的用法,parameterType为输入参数,在配置的时候,配置相应的 ...

  4. parameterType和@Param注解用法

    在mybatis映射接口的配置中,有select,insert,update,delete等元素都提到了 parameterType的用法,parameterType为输入参数,在配置的时候,配置相应 ...

  5. 9.mybatis动态SQL标签的用法

    mybatis动态SQL标签的用法 动态 SQL MyBatis 的强大特性之一便是它的动态 SQL.如果你有使用 JDBC 或其他类似框架的经验,你就能体会到根据不同条件拼接 SQL 语句有多么痛苦 ...

  6. Mybatis用法小结

    select 1.基本用法 <select id="selectTableOne" resultType="com.test.entity.tableOne&quo ...

  7. mybatis if test 用法_SpringBoot整合Mybatis-Plus 实战之动态SQL,Mybatis拿得出手的功能之一...

    MyBatis的动态SQL是最令人喜欢的功能 在了解 动态SQL之前,你首先得知道一个表达式 OGNL,这个是基础! 面试常问问题 : Mybatis 中$与#的区别? 是将传入的值当做字符串的形式, ...

  8. 深入理解MyBatis的原理(四):映射器的用法

    前言:继续深入学习 mybatis 的用法及原理,还是先会用再学习原理. 映射器的主要元素有:select.insert.update.delete.parameterMap(即将被删除,不建议使用) ...

  9. 后端技术:mybatis中resultMap用法示例笔记

    1.概念 resultMap属于mybatis返回操作结果的一个标签,可以用来映射select查询出来结果的集合,主要作用是将实体类中的字段与数据库表中的字段进行关联映射.并且支持复杂的返回结果类型. ...

最新文章

  1. html 禁止缩放 ios10,完美解决ios10及以上Safari无法禁止缩放的问题
  2. 安装和使用Oracle Instant Client 和 SQLPlus
  3. Stereo matching code
  4. python 复制文件夹校验_Python多任务复制文件夹
  5. mybatis入门基础(三)----SqlMapConfig.xml全局配置文件解析
  6. c语言设置一个选择数字的程序,C语言编一个数字益智小游戏
  7. 如何在fedora安装Telegram
  8. msfconsole攻击ftp_MSFconsole核心命令教程
  9. win7打补丁显示不适用计算机,更新win7系统提示“此更新不适用于您的计算机”如何解决...
  10. 【SpringBoot 】 组件管理 ,java工程师面试突击中华石杉
  11. 她力量系列四丨读博6年两次换导师,靠一点点“倔”,俞舟成为social chatbot的开拓者之一
  12. 为什么计算机打不开优盘,U盘打不开,且8G的U盘只报64M,为什么?
  13. Linux 服务器安装、配置和维护,一文看全~
  14. 正则表达式高级学习技巧
  15. WORD设置从开始页数算总页数
  16. 临界资源的同步与互斥,区分临界资源与临界区,二义性分析
  17. 保留两位小数的四舍五入
  18. 新/老站长如何有效推广门户网站
  19. 编写一个程序,模拟扔硬币的结果.
  20. Windows系统下的包管理器chocolatey

热门文章

  1. Java - Set 接口
  2. 计算机网络技术基础篇
  3. Cesium聚簇实现-kdbush类实现
  4. python 日历热力图_Python绘制日历图和热力图
  5. 浏览器下载软件时,默认是用迅雷下载,如何取消?
  6. 正则表达式验证系统登录密码必须由字母数字和特殊符号组成
  7. POI导出Excel(一)
  8. 集成Health Kit时因证书问题出现错误码50063的解决方案
  9. 11-20什么是内网,外网,局域网,如何判断
  10. 数组的方法-push(),pop(),unshift(),shift()