Mybatis传多个参数(三种解决方案)
2016-02-01 00:00
405 查看
第一种方案
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层调用
PrivateUser 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层方法就知道该传什么样的参数,比较直观,个人推荐用此种方案。
相关文章推荐
- 通过Java Api与HBase交互(转)
- 3中Mybatis批量查询方式
- hive与hbase整合过程
- Spring mvc进行Excel导出
- 关于Java集合总结
- 线程中的AtomicInteger和CountDownLatch
- Linux里如何查找文件内容
- IntelliJ idea mybatis插件安装
- 线程中断interrupt
- scala + intellij idea 环境搭建及编译、打包
- hive与hbase整合过程
- cookie和session
- HBase 常用Shell命令
- 解析java中volatile关键字
- IDEA插件
- TCP协议中的三次握手和四次挥手(图解)
- hive常用操作
- Hive日期格式转换用法
- java中的 FileWriter类 和 FileReader类的一些基本用法
- Spring注解@Component、@Repository、@Service、@Controller区别