第一种方案 ,通过序号传递

DAO层的函数方法

Public User selectUser(String name,String area);

对应的Mapper.xml

<select id="selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{0} and user_area=#{1}
</select>

其中,#{0}代表接收的是dao层中的第一个参数,#{1}代表dao层中第二参数,更多参数一致往后加即可。

第二种方案,通过map传递

此方法采用Map传多参数.

Dao层的函数方法

Public User selectUser(Map paramMap);

对应的Mapper.xml

<select id=" selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select>

Service层调用

Private User xxxSelectUser(){
Map paramMap=new hashMap();
paramMap.put(“userName”,”对应具体的参数值”);
paramMap.put(“userArea”,”对应具体的参数值”);
User user=xxx. selectUser(paramMap);}

个人认为此方法不够直观,见到接口方法不能直接的知道要传的参数是什么。

第三种方案,用@param通过单个参数名传递,推荐方式

Dao层的函数方法

Public User selectUser(@param(“userName”)Stringname,@param(“userArea”)String area);

对应的Mapper.xml

<select id=" selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
</select> 

第四种方案,用@param通过参数对象传递

Dao层的函数方法

Public User selectUser(@param(“user”)User user,@param(“userArea”)String area);

对应的Mapper.xml

<select id=" selectUser" resultMap="BaseResultMap">
select * from user_user_t where user_name = #{user.userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR} </select> 

每一种方式都可以不需要在xml中写parameterType属性

mybatis传递参数到mapping.xml的更多相关文章

  1. MyBatis DAO层传递参数到mapping.xml 几种方式

    Dao层传递参数到mapping.xml文件的几种方式:(Mybatis传值总结) 第一种:传递单个参数 Dao层Code片段: /** * 根据articleId查询XXXX详情. * * @par ...

  2. mybatis 传递参数的方法总结

    有三种mybatis传递参数的方式: 第一种 mybatis传入参数是有序号的,可以直接用序号取得参数 User selectUser(String name,String area); 可以在xml ...

  3. MyBatis传递参数

    MyBatis传递参数 一.使用 map 接口传递参数 在 MyBatis 中允许 map 接口通过键值对传递多个参数,把接口方法定义为 : public List<Role> findR ...

  4. mybatis传递参数的方法

    一.传递一个参数 例:根据员工编号查询员工的基本信息 1.在dao接口中声明一个方法 2.在mapper中实现该方法 3.测试 /** * 传递一个参数 */ public class Test02 ...

  5. Mybatis传递参数的几种方式

    使用Map传递 优点:直接在sql中取出key即可 缺点:适用于小项目,不符合大公司规范 对象传递参数 优点:符合标准规范 缺点:麻烦 3.只有一个基本类型参数的情况下,直接在sql中取中 4.多个参 ...

  6. Mybatis传递参数的三种方式

    第一种: Dao层使用@Param注解的方法 VersionBox getVersionByVersionNumAndVersionType(@Param("versionNum" ...

  7. mybatis 传递参数的两种方式与模糊匹配 很重要

  8. 传值:web.xml传递参数 即在Servlet中获取web.xml里的值

    传值:web.xml传递参数 在web.xml中的Servlet里配置多个init-param <servlet> ... <init-param> <param-nam ...

  9. 六、TestNG传递参数1

    TestNG可以通过testng.xml和Data Providers向测试方法传递参数 利用testNG.xml传递参数 1-创建一个TestNG测试类 其中 parameters = {" ...

随机推荐

  1. update the UI property cross thread

    this.Invoke((MethodInvoker)delegate { txtResult.Text = sbd.ToString(); // runs on UI thread });

  2. (转)C#实现MD5加密

    首先,先简单介绍一下MD5 MD5的全称是message-digest algorithm 5(信息-摘要算法,在90年代初由mit laboratory for computer science和r ...

  3. SQLALchemy(连表)、paramiko

    本节内容:

  4. MySQL分布式集群之MyCAT(转)

    原文地址:http://blog.itpub.net/29510932/viewspace-1664499/ 隔了好久,才想起来更新博客,最近倒腾的数据库从Oracle换成了MySQL,研究了一段时间 ...

  5. Project Woosah Tu (五色土)

    I bought this Raspberry Pi (model B) in spring 2013, I hadn't done too much with it except for some ...

  6. python向数据库插入数据时出现乱码解决方案

    中文字符串前面加u 如: title =u"你好" contents = "m" ids="13" cur.execute("IN ...

  7. C#对象比较

    http://www.veryhuo.com/a/view/42513.html ReferenceEquals:静态方法,不能重写,只能比较引用,如果有一个参数为null会返回false,不会抛出异 ...

  8. Dos学习笔记(2)dos屏幕内容的复制

    方法1,选择复制,右键dos屏幕=>标记=>然后选择开始复制的地方,拖动覆盖要复制的内容,好了之后,按回车键(Enter). 方法2,全部复制,右键dos屏幕=>全选=>然后回 ...

  9. jsp之tomcat安装

    安装时会碰到一个命令行窗口一闪而过的情况,里面内容是: Neither the JAVA_HOME nor the JRE_HOME environment variable is defined 是 ...

  10. algorithm 学习之 for_each

    对于algorithm里面的函数使用不算多,但是用过之后才发现,之前写过很多多余的代码,所以打算系统的学习使用下algorithm里的东西,首先就是for_each. 先看下for_each的定义: ...