Mybatis傳遞引數到mapping

2021-10-09 05:27:43 字數 960 閱讀 8857

第一種方案 ,通過序號傳遞

dao層的函式方法

public user selectuser(string name,string area);

select  *  from user_user_t   where user_name = # and user_area=#
其中,#代表接收的是dao層中的第乙個引數,#代表dao層中第二引數,更多引數一致往後加即可。

第二種方案,通過map傳遞

此方法採用map傳多引數.

dao層的函式方法

public user selectuser(map parammap);

select * from user_user_t where user_name = # and user_area=#

service層呼叫

private user ***selectuser()

個人認為此方法不夠直觀,見到介面方法不能直接的知道要傳的引數是什麼。

第三種方案,用@param通過單個引數名傳遞,推薦方式

dao層的函式方法

public user selectuser(@param(「username」)stringname,@param(「userarea」)string area);

select * from user_user_t where user_name = # and user_area=#

第四種方案,用@param通過引數物件傳遞

dao層的函式方法

public user selectuser(@param(「user」)user user,@param(「userarea」)string area);

select * from user_user_t where user_name = # and user_area=#

每一種方式都可以不需要在xml中寫parametertype屬性

mybatis傳遞引數到xml

mybatis在處理多個引數時,會將多個引數處理成param1,param2 等,但是這樣太難看了,為了簡便,我們可以使用 param註解 示例 updateuser函式 如果我們在函式中傳遞的是實體類物件,那麼我們在xml檔案中直接引用物件的屬性名就可以引用。示例 insertuser函式 在xm...

MyBatis的引數傳遞

select from student order by limit 介面 studentdao 檔案 預設引數傳遞 public listfind string sort,string dir,int start,int limit 註解方式引數傳遞 public listfind2 param ...

mybatis傳遞多個引數

據我目前接觸到的傳多個引數的方案有三種。dao層的函式方法 1 publicuserselectuser stringname,string area 1 2 3 selectid selectuser resultmap baseresultmap select fromuser user twh...