zl程序教程

您现在的位置是:首页 >  后端

当前栏目

MyBatis单个多个参数传递

mybatis 多个 单个 参数传递
2023-09-11 14:19:37 时间

一、传入单个参数:

public List<XXBean> getXXBeanList(String xxCode);  

<select id="getXXXBeanList" parameterType="java.lang.String" resultType="XXBean">

  select t.* from tableName t where t.id= #{id}  

</select>  

其中方法名和ID一致,#{}中的参数名与方法中的参数名一直, 我这里采用的是XXXBean是采用的短名字,

select 后的字段列表要和bean中的属性名一致, 如果不一致的可以用 as 来补充。

二、Map封装多参数:

public List<XXXBean> getXXXBeanList(HashMap map);  

<select id="getXXXBeanList" parameterType="hashmap" resultType="XXBean">

  select 字段... from XXX where id=#{xxId} code = #{xxCode}  

</select>  

其中hashmap是mybatis自己配置好的直接使用就行。map中key的名字是那个就在#{}使用那个。