• 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);
  • 相关阅读:
    P4047 部落划分
    P1440 求m区间的最小值
    P2880 平衡的阵容
    P2700 逐个击破
    P2814 家谱 map模版
    P4403 秦腾与教学评估
    无油无糖低脂酸奶芒果蛋糕
    紫薯铜锣烧
    Spring In Action ③
    Spring In Action ②
  • 原文地址:https://www.cnblogs.com/huey/p/5231695.html
Copyright © 2020-2023  润新知