• mybatis传入map任意表增删改查,分页过滤字段


    <!--根据实体参数查询 -->
        <select id="selectBaseList" resultType="java.util.HashMap">
            select
            *
            from ${map.tableName}
            where 1=1
            <foreach collection="map" index="key" item="value">
                <if
                    test="key != 'tableName' and key != 'pageSize' and key != 'pageNo' ">
                    and `${key}` = #{value}
                </if>
            </foreach>
            limit #{baseModel.fromRec},#{baseModel.pageSize}
        </select>
    
        <!--根据实体参数查询个数 -->
        <select id="selectBaseCount" resultType="java.lang.Integer">
            select
            count(1)
            from ${map.tableName}
            where 1=1
            <foreach collection="map" index="key" item="value">
                <if
                    test="key != 'tableName' and key != 'pageSize' and key != 'pageNo' ">
                    and  `${key}` = #{value}
                </if>
            </foreach>
        </select>
    
    
        <insert id="insertBase" parameterType="java.util.HashMap">
            insert into ${map.tableName}
            (
            <foreach collection="map" index="key" item="value"
                separator=",">
                <if test="key != 'tableName' ">
                    `${key}`
                </if>
            </foreach>
            )
            values (
            <foreach collection="map" index="key" item="value"
                separator=",">
                <if test="key != 'tableName' ">
                    #{value}
                </if>
            </foreach>
            )
        </insert>
        <update id="updateBaseByPrimaryKey">
            update ${map.tableName}
            <set>
                <foreach collection="map" index="key" item="value"
                    separator=",">
                    <if test="key != 'tableName' ">
                        `${key}`= #{value}
                    </if>
                </foreach>
            </set>
            where id = #{map.id}
        </update>

    java代码部分,baseModel中放入分页参数:

    
    
    import java.util.List;
    import java.util.Map;
    
    import org.apache.ibatis.annotations.Param;
    
    
    public interface BaseDao {
        int insertBase(@Param("map") Map map);
    
        Map selectBaseByPrimaryKey(Long id);
    
        int updateBaseByPrimaryKey(@Param("map") Map map );
    
        List<Map> selectBaseList(@Param("map") Map map, @Param("baseModel") BaseModel baseModel);
    
        int selectBaseCount(@Param("map") Map map);
    
    }
    
    
    
  • 相关阅读:
    Stockbroker Grapevine(floyd+暴力枚举)
    Moving Tables(贪心或Dp POJ1083)
    Shopping(SPFA+DFS HDU3768)
    vmware虚拟机复制后连网
    mysql 去除重复数据 语句
    flume运行问题及测试
    hadoop问题
    dfs.datanode.max.xcievers参数导致hbase集群报错
    3. Go语言基本类型
    2. Go变量(Variables)
  • 原文地址:https://www.cnblogs.com/lixiaoran/p/11563801.html
Copyright © 2020-2023  润新知