课时4:l两种取值符号以及ParameterType为简单,对象,嵌套对象类型

.1)输入参数:ParameterType

  1.类型为简单类型(8个基本类型+String)

    1.1${} 和 #{}的区别   

      (1)#{任意值}

       ${value},其中的占位符只能是value

      (2)#{}自动给String类加上‘ ’ (自动类型转换)

        ${}原样输出,但是适用于 动态排序( 动态字段)  

        动态排序的实例:

<!--    动态排序-->
    <select id="selectStudentByOrderBy" parameterType="string" resultType="student">
        select * from student order by ${value} desc
    </select>

        如果使用#{}会自动的添加‘ ‘号 就不符合数据库的语句

       (3) #{}可以防止sql注入

         ${}不防止

  2.类型是对象或者是嵌套对象类型

    2.1 对象类型

<!--    通过家庭地址或者学校地址插叙学生-->
    <select id="selectStudentByhomeOrSchool" parameterType="Address" resultType="student">
select stuno,stuName from student where homeaddress=#{homeAddress} or schooladdress='${schoolAddress}'
    </select>

       2.2 嵌套对象类型

 <!--    通过家庭地址或者学校地址插叙学生-->
    <select id="selectStudentByhomeOrSchool" parameterType="student" resultType="student">
select stuno,stuName from student where homeaddress=#{address.homeAddress} or schooladdress='${address.schoolAddress}'
    </select>

   2.2.1 #{}${}两个都支持级联 有点像EL表达式

  

 

原文地址:https://www.cnblogs.com/thisHBZ/p/12455110.html