Mybatis的多引數傳遞問題

2021-07-11 03:01:58 字數 790 閱讀 2845

申明:以下**並不是從ide工具中拷貝,是直接通過txt編輯,有可能有worry,但不會影響主體,只需稍微糾正。

1、傳遞引數以map的形式傳遞引數

在service層建立map並傳遞:

map usermap=new hashmap();

usermap.put("id",id);

usermap.put("name",name);

return this.um.selectbyidandname(usermap);

}dao層的方法如下:

user selectbyidandname(map usermap);

//(user)查詢的結果可以是物件,也可以是集合(list)

select * from user where id=# and name=#

2、傳遞引數以0、1....等方式傳遞

dao層的多引數方法如下:

user selectbyidandname(int id,string name);

select * from user where id=# and name=#

3、傳遞引數以@param的方式傳遞

dao層的多引數方法如下:

user selectbyidandname(@param(int id),@param(string name));

//注意

param的大小寫,引入的包是org.apache.ibatis.annotations.param;

select * from user where id=# and name=#

MyBatis多引數傳遞

mybatis多引數傳遞 指的是方法的引數是多個 原理 jdk的動態 spring 使用 注意 不寫返回值型別 parametertype select from account where aname and ano selac 注意 介面的方法引數就是要傳遞的引數,引數名可以使用別名,便於sql...

MyBatis引數傳遞的問題

來自 最近碰到mybatis傳參的一些問題,經過一番 問題是解決了。現對mybatis傳參進行下整理,權當做個筆記。一 單個簡單引數 public item getitembyid string id select t.c id,t.c name from titem t where t.c id ...

MyBatis介面繫結及多引數傳遞

ps 後面 mybatis 和 spring 整合時使用的是這個方案 建立乙個介面 inte ce 1 namespace 必須和介面全限定路徑 包名 類名 一致 2 id 值必須和介面中方法名相同 id selall resulttype log select from log select 在介...