zoukankan      html  css  js  c++  java
  • mybatis 动态sql(查询学习)

    Mybatis 这个框架 与书写 SQL 语句 有很大的关系,所以 在 没有 SQL 很好的 书写能力下,会遇到好多问题,本人就是例子,先将学习(查询操作中遇到的问题进行总结);

    一,<bind>标签的使用,(绑定上下文 )多用与 sql 语句中 sql 语句like 模糊查询使用;

    使用案列代码:

    <select id="getObjectByVo" resultMap="studentMap" parameterType="queryVo">
            select * from student
            <where>
                <if test="entity!=null">           
                    <if test="entity.stu_name!=null ">    
                    <bind name="stu_name" value="'%'+entity.getStu_name()+'%'"/>
                        stu_name like #{stu_name}
                    </if>                            
                </if>
            </where>
            <if test="startSize!=null and pageSize!=null">
                limit #{startSize} ,#{pageSize}
            </if>
        </select>

    二.CONAT 的使用:(字符串连接函数)

      

    stu_name like CONCAT(CONCAT('%',#{entity.stu_name},'%'"))

    替换 上面bind 的
          <bind name="stu_name" value="'%'+entity.getStu_name()+'%'"/>
                        stu_name like #{stu_name}
    添加 <if>判断条件 以防 出错!

     一起交流学习,一起进步;------------------------Ankermaker;

  • 相关阅读:
    我的暑假周记2018.7.21
    大道至简读后感
    我的暑假周记2018.7.15
    继承与多态
    java联级调用
    古罗马凯撒大帝字串加密
    作业三
    线性同余法产生1000个随机数
    Text2
    java登录界面
  • 原文地址:https://www.cnblogs.com/Ankermaker/p/6950336.html
Copyright © 2011-2022 走看看