mapper.xml

mapper.xml

<?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="xxxDao">

    <resultMap type="xxx" id="aaa">
        <result property="id" column="id" jdbcType="INTEGER"/>
		<result property="xxx_xxx" column="xxxXxx" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="tab_column">
        xxx, xxx2
    </sql>

	<sql id="tab_column_no_id">
        xxx, xxx2
    </sql>


    <!-- 实体属性 -->
    <sql id="domain_properties">
        #{xxx},
        #{xxxXxx}
    </sql>

    <!--查询单个-->
    <select id="queryById" resultMap="aaa">
        select
          <include refid="tab_column"/>
        from xxx
        where id = #{id}
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="queryAll" resultMap="aaa">
        select
        <include refid="tab_column"/>
        from xxx
        <where>
            <if test="xx != null">
                and xx= #{xx}
            </if>
            <if test="xx != null and xx != ''">
                and xx = #{xxXx}
            </if> 
        </where>
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into xxx(<include refid="tab_column"/>)
        values (<include refid="domain_properties"/>)
    </insert>


    <insert id="insertBatch" keyProperty="id" useGeneratedKeys="true" parameterType="map">
        insert into xxx(<include refid="tab_column_no_id"/>)
        values
        <foreach collection="entities" item="entity" index="index" separator=",">
            (#{entity.xxx}, #{entity.xxxXxx})
        </foreach>
    </insert>

    <insert id="insertOrUpdateBatch" keyProperty="id" useGeneratedKeys="true" parameterType="map">
        insert into xxx(<include refid="tab_column"/>)
        values
        <foreach collection="entities" item="entity" index="index" separator=",">
           (#{entity.xxx}, #{entity.xxxXxx})
        </foreach>
        on duplicate key update
        xxx= values(xxx) , xxx_xxx = values(xxx_xxx)
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update xxx
        <set>
            <if test="xxx != null and xxx != ''">
                xxx= #{xxx},
            </if>
            <if test="xxxXxx != null and xxxXxx != ''">
                xxx_xxx = #{xxxXxx}
            </if>
        </set>
        where id = #{id}
    </update>

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

</mapper>

 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值