zoukankan      html  css  js  c++  java
  • MyBatis高级查询

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE mapper
            PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
            "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
    
    <!-- namespace表示命名空间  保证它是唯一   cn.itsource.mybatis.dao.impl.ProductDaoImpl + id="getUserById"-->
    <mapper namespace="_02_highquery.EmployeeMapper">
        <!-- id名称和ProductMapper接口方法一样-->
        <select id="query" resultType="_02_highquery.Employee" parameterType="_02_highquery.EmployeeQuery">
            select * from employee
            <where>
                <include refid="whereSql"></include>
            </where>
        </select>
        <!--抽取sql通过include refid="whereSql"引用-->
        <sql id="whereSql">
            <if test="keywords != null">
                <!-- /* and name like %${keywords}% or password like %${keywords}%*/ -->
                <!-- (1)不行-->
                <!--  and name like %#{keywords}% or password like %#{keywords}% -->
                <!-- (2)可以使用 拼接字符串 存在sql注入-->
                <!-- and name like '%${keywords}%' or password like '%${keywords}%' -->
                <!-- (3) concat函数-->
                  and name like concat("%",#{keywords},"%")
            </if>
            <if test="minAge != null">
                and age >= #{minAge}
            </if>
            <!-- 转义1)-->
    
            <!--<if test="maxAge != null">
                and age &lt;= #{maxAge}
            </if>-->
            <!-- 写法(2)CDATA XML-->
            <if test="maxAge != null">
                <![CDATA[
                     and age <= #{maxAge}
                  ]]>
            </if>
        </sql>
    
    
    
    
    
    
    </mapper>
  • 相关阅读:
    四、面向对象分析和设计全流程概述
    三、三大核心特征-继承
    二、三大核心特征-多态
    [第三章]一、三大核心特征-封装
    四、抽象类
    三、接口
    二、对象
    [第二章]一、类
    六、面向对象的迷思
    五、面向对象的应用范围
  • 原文地址:https://www.cnblogs.com/xiaoruirui/p/11776283.html
Copyright © 2011-2022 走看看