mysql map 参数_架构师之mybatis-----传入传出多个参数,都是map,批量更新

本文介绍了在MyBatis中如何使用Map作为参数进行查询,并给出了批量更新的例子。通过Map传递多个参数,如beginTime和endTime,进行数据库查询。在Oracle和MySQL中,批量更新的配置有所不同,对于MySQL,需要设置`allowMultiQueries=true`才能执行批量更新操作。
摘要由CSDN通过智能技术生成

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}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值