PlatTenantMapper.xml 3.67 KB
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.diligrp.mqtt.web.mapper.PlatTenantMapper">

    <resultMap type="com.diligrp.mqtt.web.model.PlatTenant" id="PlatTenantMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="name" jdbcType="VARCHAR"/>
        <result property="privateKey" column="private_key" jdbcType="VARCHAR"/>
    </resultMap>

    <!--查询单个-->
    <select id="queryById" resultMap="PlatTenantMap">
        select id,
               name,
               private_key,
               public_key
        from plat_tenant
        where id = #{id}
    </select>

    <!--查询指定行数据-->
    <select id="queryAllByLimit" resultMap="PlatTenantMap">
        select
        id, name, private_key
        from plat_tenant
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="privateKey != null and privateKey != ''">
                and private_key = #{privateKey}
            </if>
            <if test="publicKey != null and publicKey != ''">
                and public_key = #{publicKey}
            </if>
        </where>
        limit #{pageable.offset}, #{pageable.pageSize}
    </select>

    <!--统计总行数-->
    <select id="count" resultType="java.lang.Long">
        select count(1)
        from plat_tenant
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and name = #{name}
            </if>
            <if test="privateKey != null and privateKey != ''">
                and private_key = #{privateKey}
            </if>
            <if test="publicKey != null and publicKey != ''">
                and public_key = #{publicKey}
            </if>
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into plat_tenant(name, private_key, public_key)
        values (#{name}, #{privateKey}, #{publicKey})
    </insert>

    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true">
        insert into plat_tenant(name, private_key, public_key)
        values
        <foreach collection="entities" item="entity" separator=",">
        (#{entity.name}, #{entity.privateKey}, #{entity.publicKey})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true">
        insert into plat_tenant(name, private_key, public_key)
        values
        <foreach collection="entities" item="entity" separator=",">
            (#{entity.name}, #{entity.privateKey}, #{entity.publicKey})
        </foreach>
        on duplicate key update
        name = values(name),
        private_key = values(private_key),
        public_key = values(public_key)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update plat_tenant
        <set>
            <if test="name != null and name != ''">
                name = #{name},
            </if>
            <if test="privateKey != null and privateKey != ''">
                private_key = #{privateKey},
            </if>
            <if test="publicKey != null and publicKey != ''">
                public_key = #{publicKey},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from plat_tenant where id = #{id}
    </delete>

</mapper>