MyBatis引數傳遞的問題

2021-08-27 11:26:36 字數 2335 閱讀 1438

來自:

最近碰到mybatis傳參的一些問題,經過一番**,問題是解決了。

現對mybatis傳參進行下整理,權當做個筆記。

一、單個簡單引數

public item getitembyid(string id);

select t.c_id, t.c_name

from titem t

where t.c_id = #

二、多個簡單引數

public listgetitemlist(string type, string color);

select t.c_id, t.c_name, t.c_type, t.c_color

from titem

where t.c_type = #

and t.c_color = #

不能使用parametertype,使用#獲取引數,索引從0開始

三、多引數註解傳遞

public listgetitemlist(@param("type") string type, @param("color") string color);

select t.c_id, t.c_name, t.c_type, t.c_color

from titem

where t.c_type = #

and t.c_color = #

四、map封裝多引數

public listgetitemlist(hashmap map);

select t.c_id, t.c_name, t.c_type, t.c_color

from titem

where t.c_type = #

and t.c_color = #

hashmap為mybatis配置,可直接使用。

五、list封裝,in呼叫

public listgetitemlist(listlist);

select t.c_id, t.c_name, t.c_type, t.c_color

from titem

where t.c_type in

#

六、list與string同時需要

listtype = new arraylist();

type.add("1");

type.add("2");

mapmap = new hashmap();

map.put("list", list);

map.put("color", "red");

public listgetitemlist(mapmap)

select t.c_id, t.c_name, t.c_type, t.c_color

from titem

where t.c_color = #

and t.c_type in

#

70221322/article/details/77128551

Mybatis的多引數傳遞問題

申明 以下 並不是從ide工具中拷貝,是直接通過txt編輯,有可能有worry,但不會影響主體,只需稍微糾正。1 傳遞引數以map的形式傳遞引數 在service層建立map並傳遞 map usermap new hashmap usermap.put id id usermap.put name ...

MyBatis的引數傳遞

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

mybatis的mapper引數傳遞

簡單引數傳遞是指 actor selectactorbyid long id select id selectactorbyid resulttype canger.study.chapter04.bean.actor select actor id as id,first name as firs...