第一种:按序列传参
Public User selectUser(String name,String area);
<
select
id=
"selectUser"
resultMap=
"BaseResultMap"
>
select
*
from
user_user_t
where
user_name = #{0}
and
user_area=#{1}
</
select
>
第二种:基本数据类型(parameterType="xxx")(接口方法声明参数中可使用注解@param(“xx”),一个参数时可以不用加@param,多个参数是就要用@param了。)
List<Teacher> tList = teacherMapper.selectTeacher(2);
<select id="selectTeacher" parameterType="int" resultType="com.myapp.domain.Teacher">
select * from Teacher where c_id=#{id}
</select>
select * from Teacher where c_id=#{id}
</select>
第三种:JAVA实体类
Teacher queryTeacher=new Teacher();
queryTeacher.setId(2);
List<Teacher> tList = teacherMapper.selectTeacher(queryTeacher);
queryTeacher.setId(2);
List<Teacher> tList = teacherMapper.selectTeacher(queryTeacher);
<select id="selectTeacher" parameterType="com.myapp.domain.Teacher" resultType="com.myapp.domain.Teacher">
select * from Teacher where c_id=#{id}
</select>
select * from Teacher where c_id=#{id}
</select>
第四种:Map
Map<String,String> map=new HasMap<String,String>();
map.put("id","2");
map.put("sex","男");
List<Teacher> tList = teacherMapper.selectTeacher(map);
map.put("id","2");
map.put("sex","男");
List<Teacher> tList = teacherMapper.selectTeacher(map);
<select id="selectTeacher" parameterType="Map" resultType="com.myapp.domain.Teacher">
select * from Teacher where c_id=#{id} and sex=#{sex}
</select>
select * from Teacher where c_id=#{id} and sex=#{sex}
</select>