1.前言.
如题.
2.代码.
(1)mapper.xml.
select count(1) as c1,userid as c2 from test where insertime =]]> #{beginTime,jdbcType=TIMESTAMP} and insertime #{endTime,jdbcType=TIMESTAMP} group by userid
(2)interface
public interface TestMapper{
List> getTest(Map map);
}
(3)
测试类:
@Test
public void test3(){
SimpleDateFormat sf=new SimpleDateFormat("yyyyMMddHH");
Date d1 = null;
try {
d1 = sf.parse("2014061100");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Date d2 = null;
try {
d2 = sf.parse("2014121100");
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//new
Map map=new HashMap();
map.put("beginTime", d1);
map.put("endTime", d2);
List list=testMapper.getTest(map);
System.out.println(list.size());
}
2.批量更新.
参考外链网址已屏蔽:
oracle和mysql数据库的批量update在mybatis中配置不太一样:
oracle数据库:
update test
test=${item.test}+1
where id = ${item.id}
mysql数据库:
mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
update test
test=${item.test}+1
where id = ${item.id}