MyBatis(3.2.3)

MyBatis's mapped statements have the parameterType attribute to specify the type of input parameter. If we want to pass multiple input parameters to a mapped statement, we can put all the input parameters in a HashMap and pass it to that mapped statement.

MyBatis provides another way of passing multiple input parameters to a mapped statement. Suppose we want to find students with the given name and email.

public interface StudentMapper {
    List<Student> findAllStudentsByNameEmail(String name, String email);
}

MyBatis supports passing multiple input parameters to a mapped statement and referencing them using the #{param} syntax.

<select id="findAllStudentsByNameEmail" resultMap="StudentResult">
    select stud_id, name,email, phone from Students where name = #{param1} and email = #{param2}
</select>

Here #{param1} refers to the first parameter name and #{param2} refers to the second parameter email.

StudentMapper studentMapper = sqlSession.getMapper(StudentMapper.class);
studentMapper.findAllStudentsByNameEmail(name, email);
原文地址:https://www.cnblogs.com/huey/p/5231695.html