dao传递类参数 mybatis,MyBatis!将多个参数传递给Mapper DAO

在DAO实现中,如果你需要向Mapper方法传递多个参数,可以使用HashMap来实现。例如,对于`obj.getName(int a, int b)`这样的需求,你可以在`getAllName()`方法中创建一个HashMap,将参数`a`和`b`作为键值对放入,然后在Mapper的XML文件中通过键来访问这些参数。
摘要由CSDN通过智能技术生成

I am trying to send multiple parameter to Mapper function defined in DAO implementation but unable to send more than 1 parameter in the case when parameter are not holder of any class.

I mean how can I modify the following code-

obj.getName(int a, int b);

In DAO implementation

public void getAllName() throws PersistenceException {

SqlSession session = sf.openSession();

try {

session.selectList("getNames");

} finally {

session.close();

}

}

I want to send a and b to query getNames.

Thanks in advance.

解决方案

If you are using DAO implementation then you can do this by using a HashMap. Just add the key-value pair in HashMap and add it in function call and you can access it in the mapper.xml using "key".

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值