mybaits中多个参数传入使用
来源:互联网 发布:糊是什么意思网络语言 编辑:程序博客网 时间:2024/06/05 03:03
据我目前接触到的传多个参数的方案有三种。
第一种方案
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传多参数.
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);}
个人认为此方法不够直观,见到接口方法不能直接的知道要传的参数是什么。
第三种方案
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>
个人觉得这种方法比较好,能让开发者看到dao层方法就知道该传什么样的参数,比较直观,个人推荐用此种方案。
阅读全文
0 0
- mybaits中多个参数传入使用
- mybaits中传入数组参数
- mybaits 多个参数传入用#{0,1,....}或者@Param注释
- mybaits 多个参数传入用#{0,1,....}或者@Param注释
- mybaits使用
- Activator.CreateInstance使用中的参数传入
- mybatis使用map传入多个参数
- Java使用MyBatis传入参数的问题
- JDBC传入参数使用LIKE模糊搜索
- MyBatis传入参数与parameterType不同类型使用
- 使用mybatis时paramType传入参数总结
- MyBaits参数传递注意事项
- Mybaits的参数详解
- 传入参数
- jsp使用传入参数作为查库参数
- Jmeter使用_time函数实现同一个接口参数传入可以每次传入不同的参数
- MyBaits传递多个参数
- mybaits Condition使用
- Java 多线程之synchronized关键字详解
- 那些亮瞎你的奇葩癖好!别再说程序猿不会玩了
- 博客系统开发推送第六季----留言板模块
- Tomcat基本使用
- 探索性数据分析
- mybaits中多个参数传入使用
- 获取设备的局域网IP
- git 操作方法
- mybatis小坑总结
- MySQL里面的子查询
- stylus之内置方法(Built-in Functions)
- 笑谈java并发编程五之AtomicLong*介绍
- java虚拟机内存分布
- 开发笔记