mybatis传递Map和List集合示例
1、List示例
java文件:
dao:
public List<ServicePort> selectByIps(List<String> ips);
xml文件:
<!-- 高级查询 -->
<select id="selectByIps" resultType="ServicePort">
Select *
from port_service_info where ip in
<foreach item="item" index="index" collection="list"
open="(" separator="," close=")">
#{item}
</foreach>
</select>
2、Map示例
java文件:
service:
public List<TamperAndHijack> selectByDomains(List<String> domains, String dayKey) {
Map<String, Object> map = new HashMap<String, Object>();
//不存在就查询所有
if(domains.isEmpty()){
domains = null;
}
map.put("domains", domains);
//默认为当天
if(dayKey == null || "".equals(dayKey)){
dayKey = CommonUtil.getCurrentDateStr();
}
map.put("dayKey", dayKey);
return tamperAndHijackMapper.selectByDomains(map);
}
dao:
/** 通过domains查询指纹信息 */
public List<TamperAndHijack> selectByDomains(@Param("map")Map<String, Object> map);
xml文件:
<!-- 高级查询 -->
<select id="selectByDomains" parameterType="map" resultType="TamperAndHijack">
Select *
from tamper_hijack
where 1 = 1
<if test="map.dayKey !=null and map.dayKey !=''">
and dayKey = #{map.dayKey}
</if>
<if test="map.domains !=null">
and domain in
<foreach item="item" index="index" collection="map.domains"
open="(" separator="," close=")">
#{item}
</foreach>
</if>
order by id desc
</select>
mybatis传递Map和List集合示例的更多相关文章
- Mybatis传递多个参数的几种方式
顺序传参法 public User selectUser(String name, int deptId); <select id="selectUser" resultMa ...
- MyBatis传递参数
MyBatis传递参数 一.使用 map 接口传递参数 在 MyBatis 中允许 map 接口通过键值对传递多个参数,把接口方法定义为 : public List<Role> findR ...
- MyBatis多参数传递之注解方式示例--转
原文地址:http://legend2011.blog.51cto.com/3018495/1015003 若映射器中的方法只有一个参数,则在对应的SQL语句中,可以采用#{参数名}的方式来引用此参数 ...
- mybatis 传递参数的方法总结
有三种mybatis传递参数的方式: 第一种 mybatis传入参数是有序号的,可以直接用序号取得参数 User selectUser(String name,String area); 可以在xml ...
- mybatis传递多个参数值(转)
Mybatis传递多个参数 ibatis3如何传递多个参数有两个方法:一种是使用Map,另一种是使用JavaBean. <!-- 使用HashMap传递多个参数 para ...
- Mybatis传递多个参数进行SQL查询的用法
当只向xxxMapper.xml文件中传递一个参数时,可以简单的用“_parameter”来接收xxxMapper.java传递进来的参数,并代入查询. 但是,如果在xxxMapper.java文件中 ...
- 手写Mybatis和Spring整合简单版示例窥探Spring的强大扩展能力
Spring 扩展点 **本人博客网站 **IT小神 www.itxiaoshen.com 官网地址****:https://spring.io/projects/spring-framework T ...
- JAX-WS:背后的技术JAXB及传递Map
转载:http://www.programgo.com/article/98912703200/ 1.什么是JAX-WS JAX-WS (JavaTM API for XML-Based Web Se ...
- Activity之间通过intent 传递Map
//传递 Map<String,Object> data=orderlist.get(arg2-1); SerializableMap tmpmap=new SerializableMap ...
随机推荐
- C# 遍历枚举(枚举是目的,遍历(获取)是手段)
C# 遍历枚举 C#中,如何获取(遍历)枚举中所有的值: public enum Suits { Spades, Hearts, Clubs, Diamonds, NumSuits } priva ...
- animation几个比較好玩的属性(alternate,及animation-fill-mode)
<!DOCTYPE html> <html> <head> <style> div { width:100px; height:100px; backg ...
- maven(2)------maven构建项目
一 下载maven 官网地址: http://maven.apache.org/download.cgi 如图: 可以下载历史版本. 二 windows下maven配置 1. 解压下载后的包,解压后 ...
- mysql从文件中导入数据
linux: load data infile '/tmp/dnslog.txt' into table dnslog_cnnic_cn fields terminated by ' ' lines ...
- VC中使用Matlab Engine出现"无法找到libeng.dll"的问题
VC中使用Matlab Engine出现"无法找到libeng.dll"的问题 本以为使这个原因 ,其实不是我2了 #include "engine.h" // ...
- 对象的操作-javascript
任务要求: 每单机一下div,边框各加5px,且会红色跟黑色相互交替. 学习总结: 主要是学习到了parseInt这个函数.主要是将本身设置好的长宽然后再加5像素的时候需要用到该函数.如果直接加不使用 ...
- 查看局域网其它电脑的计算机名和IP
一.下面脚本可查看局域网中的电脑计算机名和IP,保存下面文本至记事本.后缀改成bat COLOR 0A CLS @ECHO Off Title 查询局域网内在线电脑IP :send @ECHO off ...
- 线程池 ManualResetEvent
线程池: “线程池”是可以用来在后台执行多个任务的线程集合.(有关背景信息,请参见使用线程处理.)这使主线程可以自由地异步执行其他任务. 线程池通常用于服务器应用程序.每个传入请求都将分配给线程池中的 ...
- C#多线程解决界面卡死问题的完美解决方案,BeginInvoke而不是委托delegate 转载
问题描述:当我们的界面需要在程序运行中不断更新数据时,当一个textbox的数据需要变化时,为了让程序执行中不出现界面卡死的现像,最好的方法就是多线程来解决一个主线程来创建界面,使用一个子线程来执行程 ...
- JAVA用POI读取和创建2003和2007版本Excel完美示例
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import ja ...