zoukankan      html  css  js  c++  java
  • mybatisplus 自定义sql 使用条件构造器

    Mybatisplus 自定义sql 使用条件构造器

    两种方式

    注解方式

    动态查找:
    @Select("select ${ew.SqlSelect} from ${tableName} ${ew.customSqlSegment}")
    List<File> listFileByCondition(@Param("tableName") String tableName, @Param("ew") Wrapper wrapper);
    
    ew.SqlSelect:所需要查找的字段
    
    tableName:使用的是那张表
    
    ew.customSqlSegment:条件
    用法:allFileMapper.listFileByCondition(tableName,Wrappers.query().select("*").in("relation_uuid", uuids));
    结果: select * from tablName where relation_uuid in ()
    
    
    动态修改:
    @Update("update ${tableName} set ${ew.sqlSet} ${ew.customSqlSegment}")
    int updateByCondition(@Param("tableName") String tableName, @Param("ew") Wrapper wrapper);
    
    ew.sqlSet:修改的字段
    
    tableName:使用的是那张表
    
    ew.customSqlSegment:条件
    
    用法:
    mapper.updateByCondition(tableName, Wrappers.update().set("state", "初始状态").in("id", ids));
    结果: update tableName set state = '初始状态' where id in ()
    

    xml方式

    查找:
    <select id="listFileByCondition" resultType="com.example.entity.File">
    	SELECT ${ew.SqlSelect} FROM ${tableName} ${ew.customSqlSegment}
    </select>
    
    
    修改:
    <update id="listFileByCondition" >
    	update ${tableName} ${ew.SqlSelect}  ${ew.customSqlSegment}
    </update>
    

    查找带分页

    xml用法:
    Page<File> selectPage(Page page, @Param("tableName") String tableName, @Param("ew") Wrapper wrapper);
    
    <select id="selectPage" resultType="com.example.entity.File">
            select * from ${tableName} ${ew.customSqlSegment}
    </select>
    
    注解分页:
    
    
  • 相关阅读:
    【原创】深入理解c++的右值引用
    【原创】c++拷贝初始化和直接初始化的底层区别
    【原创】Github团队协作之Pull请求
    【原创】基于多线程的银行家算法设计
    【原创】Git删除暂存区或版本库中的文件
    【笔记】程序员的思维修炼3
    【笔记】德雷福斯模型
    【原创】GC/垃圾回收简介
    数据库——JavaWEB数据库连接
    多线程
  • 原文地址:https://www.cnblogs.com/java-hardly-road/p/11088486.html
Copyright © 2011-2022 走看看