MyBatis传入多个参数
1.单个参数
<select id="selectById" resultType="student" parameterType="string">
<include refid="All"></include>
where s_id = #{s_id}
</select>
Mapper:
Student stu = sqlSession.selectOne("student.selectById", "01");
2.多个参数–索引取值1
@Select("select * from student where s_id = #{arg0} and s_name = #{arg1} and s_sex = #{arg2}")
Student selectOne1(String s_id, String s_name, String s_sex);
Student student = mapper.selectOne2("01", "赵雷", "男");
3.索引取值2
@Select("select * from student where s_id = #{param1} and s_name = #{param2} and s_sex = #{param3}")
Student selectOne2(String s_id, String s_name, String s_sex);
Student student = mapper.selectOne2("01", "赵雷", "男");
4.@Parm注解方式
@Select("select * from student where s_id = #{p1} and s_name = #{p2} and s_sex = #{p3}")
Student selectOne3(@Param("p2") String s_name, @Param("p1") String s_id, @Param("p3") String s_sex);
Student student = mapper.selectOne3( "赵雷", "01","男");
参数的顺序可以打乱
5.Map传参—万能方式
<select id="selectDou" resultType="student" parameterType="Hashmap">
select *
from student
where s_id = #{s_id} and s_name = #{s_name}
</select>
HashMap<String, Object> map = new HashMap<>();
map.put("s_name","赵雷");
map.put("s_id","01");
Student student = sqlSession.selectOne("student.selectDou",map);
6.list传参