zoukankan      html  css  js  c++  java
  • Mybatis(三)MyBatis 动态SQL

    在 MyBatis 3 之前的版本中,使用动态 SQL 需要学习和了解非常多的标签,现在 MyBatis 采用了功能强大的 OGNL( Object-Graph Navigation Language)表达式语言消除了许多其他标签, 以下是 MyBatis 的动态 SQL 在 XML 中支持的几种标签 。

    • if
    • choose(when、oterwise)
    • trim(where、set)
    • forrach
    • bind

    if:通常用于 查询或修改where条件、 修改时是否修改某个字段、insert时判断是否插入某个字段。

    select * from table where 1=1

    <if test="userName != null and userName !='' "> and user name like concat('%',#{userName}, '%') </if>

    这里的 where 1=1是要带着的,如果是写在<where>标签中就不用带了。

  • 相关阅读:
    软件原则
    Optional
    雪花算法原理
    AOP
    trycatchfinally
    lambda表达式
    BeanUtils属性转换工具
    @Transactional 失效
    用户线程&&守护线程
    卡顿问题
  • 原文地址:https://www.cnblogs.com/cuiqq/p/11155546.html
Copyright © 2011-2022 走看看