传单个参数
单个参数:mybatis不会做特殊处理,#{参数名/任意名}:取出参数值。
传多个参数
方法一
public Employee getEmpByIdAndLastName(Integer id,String lastName);
mybatis:
<select id="getEmpByIdAndLastName" resultType="com.mybatis.bean.Employee">
select * from tbl_employee where id = #{0} and last_name=#{1}
</select>
<!--或者 -->
<select id="getEmpByIdAndLastName" resultType="com.mybatis.bean.Employee">
select * from tbl_employee where id = #{Param1} and last_name=#{Param2}
</select>
方法二
public Employee getEmpByIdAndLastName(@Param("id")Integer id,@Param("lastName")String lastName);
mybatis:
<select id="getEmpByIdAndLastName" resultType="com.mybatis.bean.Employee">
select * from tbl_employee where id = #{id} and last_name=#{lastName}
</select>