一、傳入單個參數:
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的名字是那個就在#{}使用那個。