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);

 

相关文章:

  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2021-06-08
猜你喜欢
  • 2021-11-11
  • 2022-12-23
  • 2022-12-23
  • 2021-09-18
  • 2022-12-23
  • 2021-09-08
  • 2021-07-05
相关资源
相似解决方案