006mybatis动态sql

bind (模糊查询,前后缀补充)

bind 标签是通过 OGNL 表达式去定义一个上下文的变量

SysUser sysUser1 = new SysUser();
sysUser1.setUserName("Kong");
List sysUsers = sysUserMapper.selectByUserLike(sysUser1);
select *
    from sys_user
    
    where user_name like #{userNameLike}

        where 1=1 的条件拼装


    user_code = #{userCode,jdbcType=VARCHAR}


    and user_name = #{userName}

set

        会自动去掉语句后面多余的逗号


  
  UPDATE tab_omin_cm_cc_intf_tv
    
            C_URL_PARAM = #{cUrlParam},
            C_TABLE_NAME = #{cTableName},
    
   WHERE  C_INTF_TV_ID = #{cIntfTvId}

collection: 必填, 集合/数组/Map的名称

item: 变量名。 即从迭代的对象中取出的每一个值

index: 索引的属性名。 当迭代的对象为 Map 时, 该值为 Map 中的 Key

open: 循环开头的字符串

close: 循环结束的字符串

separator: 每次循环的分隔符

批量新增

Integer  batchInsert(List sysUsers);

    insert into sys_user ( user_code, user_name, user_password, user_state)
            values
    
        (
         #{user.userCode},
         #{user.userName},
         #{user.userPassword},
         #{user.userState})
    

IN

List  selectByIdsAndUserName( List ids, String userName);

choose when otherwise

一个 choose 标签至少有一个 when, 最多一个otherwise

SELECT
    
        
            
                ${column}
            
        
        
            *
        
    
FROM
    ${tableName}

    
        
            ${map.c_logic} ${map.c_param_key} ${map.c_param_operator}
            
                
                    
                    #{pattern}
                
                
                    
                    #{pattern}
                
                
                    
                    #{pattern}
                
                
                    #{map.value}
                
            
        
    

ORDER BY version DESC, c_updated_date DESC

Trim

prefix:  trim 元素包含有内容时, 增加 prefix 所指定的前缀

prefixOverrides: 当 trim 元素包含有内容时, 去除 prefixOverrides 指定的 前缀

suffix: 当 trim 元素包含有内容时, 增加 suffix 所指定的后缀

suffixOverrides: 当 trim 元素包含有内容时, 去除 suffixOverrides 指定的后缀

 
        UPDATE 
          `blog` 
        
         author_id = #{authorId},
        
        WHERE `id` = #{id}
     
  
        select * from blog 
            
               lower(title) like lower(#{title})
        

你可能感兴趣的:(mybatis,sql,mybatis,java)