通常来说需要在select标签中添加 parameterType 属性,但可以省去。通过在SQL查询语句中用 #{变量名} 可以插入给定参数。

使用 #{} 而非 ${} 可以增加安全性,实际上前者就是用 JDBC中的PreparedStatement来实现:

<select id="selectStudent" resultMap="test">  
    select * from student where Sno = #{sid}  
</select>

此时就可以在包装类中修改方法参数:

public interface TestMapper {  
    List<Student> selectStudent(int sid);  
}

主函数中调用即可:

List<Student> student = testMapper.selectStudent(211164297);