zoukankan      html  css  js  c++  java
  • 两种取值符号的异同

    输入参数:parameterType
    1.输入为简单类型(八个基本类型+String)
    a.#{}  ${}
    #{任意值}
    ${value},其中的标识符只能是value

     <select id="queryStudentByStuno" parameterType="int" resultMap="studentMapping">
        select * from student1 where stuno=#{任意值}
    </select> <select id="queryStudentByStuno" parameterType="int" resultMap="studentMapping"> select * from student1 where stuno=${value}
    </select>

    b.#{}自动给String类型加上单引号(自动类型转换)

    ${}原样输出,但是适合于动态排序

    delete from student1 where stuno=#{value}
    delete from student1 where stuno='${value}'
     <select id="queryStudentOrderByColumn" resultType="student">
        select stuno,stuname,stuage from student1 order by ${value} asc
      </select>//排序成功
    
     <select id="queryStudentOrderByColumn" resultType="student">
        select stuno,stuname,stuage from student1 order by #{value} asc
       </select>//排序无效

    c.#{}可以防止sql注入

    ${}不可以

    #{}${]相同之处

    a.都可以获得对象的值(嵌套类型对象)

    i.获取对象值:

    模糊查询方式一:

    select stuno,stuname,stuage from student1 where stuage=#{stuAge} or stuname like #{stuName}

    Student student=new Student();

    student.setStuAge(23);
    student.setStuName("%m%");
    List<Student> students = studentMapper.queryStudentByStuageOrStuname(student);

    模糊查询方式二:

    select stuno,stuname,stuage from student1 where stuage=#{stuAge} or stuname like '%${stuName}%'
    
    
    Student student=new Student();
    student.setStuAge(23);
    student.setStuName("%m%");
    List
    <Student> students = studentMapper.queryStudentByStuageOrStuname(student);

    ii.嵌套类型对象

    <select id="queryStudentByaddress" parameterType="student" resultType="student">
        select stuno,stuname,stuage from student1 where homeaddress=#{address.homeAddress} or schooladdress='${address.schoolAddress}'
     </select>
    
    
    
            
    Address address=new Address();
    address.setHomeAddress("china");
    address.setSchoolAddress("x");
            
    Student student=new Student();
    student.setAddress(address);
    List<Student> students = studentMapper.queryStudentByaddress(student);
  • 相关阅读:
    springboot以jar运行时参数传递
    linux 下ab压力测试
    Quartus 11生成pof文件在AS烧写之后,程序无法启动
    芯片底层热焊盘的焊接
    CC3200模块的内存地址划分和bootloader,启动流程(二)
    python开发记录第一篇
    windows下使用Python出现No module named tkinter.ttk
    Pycharm设置Python的路径
    Qsys配置生成nios系统模块
    sprintf()函数使用异常
  • 原文地址:https://www.cnblogs.com/mayouyou/p/13214814.html
Copyright © 2011-2022 走看看