【转载】mybatis动态sql

一、mybatis动态sql语句功能简介

1.动态 SQL是MyBatis强大特性之一。极大的简化我们拼装SQL的操作。
2.MyBatis 采用功能强大的基于 OGNL 的表达式来简化操作。支持的主要属性如下:

  • if
  • choose(when, otherwise)
  • trim (where, set)
  • foreach

二、具体使用

1. if(用于条件判断)


2.choose、when、others(用于if-else类似的条件判断)

select id="chooseInWhere" resultMap="userMap">
        select * from user where 1=1
        
            
                and id=#{id}
            
            
                and id=2
            
        
    

3.where(用于sql语句where条件判断)


4.set(用于更新数据时候使用)


     update user 
     
     
                 user_name=#{userName}
            
     
     where id =#{id}
    

5.foreach(用于批量插入时候结合in使用)


转载:5.mybatis动态sql

你可能感兴趣的:(【转载】mybatis动态sql)