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中放入分頁參數:java

 
 
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); }
相關文章
相關標籤/搜索