1.map传参数:相当于serviceImpl层
Map<String, Object> params = new HashMap<String, Object>();
params.put("email", email);
params.put("sex", sex);
List<TUser> list1 = mapper.selectByEmailAndSex1(params);
mapper层:
List<TUser> selectByEmailAndSex2(@Param("email")String email,@Param("sex")Byte sex);
xml层:
<select id="selectByEmailAndSex2" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_user a
where a.email like CONCAT('%', #{email}, '%') and
a.sex = #{sex}
</select>
2.直接传入参数形式:
serviceImpl层:
List<TUser> list2 = mapper.selectByEmailAndSex2(email, sex);
mapper层:
List<TUser> selectByEmailAndSex2(@Param("email")String email,@Param("sex")Byte sex);
xml层:
<select id="selectByEmailAndSex2" resultMap="BaseResultMap">
select
<include refid="Base_Column_List" />
from t_user a
where a.email like CONCAT('%', #{email}, '%') and
a.sex = #{sex}
</select>
3.对象形式传参:
serviceImpl
EmailSexBean esb = new EmailSexBean();
esb.setEmail(email);
esb.setSex(sex);
List<TUser> list3 = mapper.selectByEmailAndSex3(esb);
mapper层:
List<TUser> selectByEmailAndSex3(EmailSexBean esb);
xml层:
<select id="selectByEmailAndSex3" resultMap="BaseResultMap"
parameterType="com.enjoylearning.mybatis.entity.EmailSexBean">
select
<include refid="Base_Column_List" />
from t_user a
where a.email like CONCAT('%', #{email}, '%') and
a.sex = #{sex}
</select>