zoukankan      html  css  js  c++  java
  • mybatis 动态curd

    xml

        <select id="selectByCondition" parameterType="com.oracle.pojo.Student" resultType="com.oracle.pojo.Student" >
            select id,name,address,gender,age 
            from student
            where 1=1
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null">
                and name = #{name}
            </if>    
            <if test="address != null">
                and address like #{address}
            </if>
            <if test="gender != null">
                and gender = #{gender}
            </if>
            <if test="age != 0">
                and age = #{age}
            </if>
        </select>
        
        
        
        
        <sql id="key">
            <trim suffixOverrides=",">
                id,
                <if test="name !=null">
                    name,
                </if>
                <if test="address !=null">
                    address,
                </if>
                <if test="gender != null">
                    gender,
                </if>
                <if test="age != 0">
                    age,
                </if>
            </trim>
        </sql>
        <sql id="values">
            <trim suffixOverrides=",">
                #{id},
                <if test="name !=null">
                    #{name},
                </if>
                <if test="address !=null">
                    #{address},
                </if>
                <if test="gender != null">
                    #{gender},
                </if>
                <if test="age != 0">
                    #{age},
                </if>
            </trim>
        </sql>
        <insert id="dynainsert" parameterType="com.oracle.pojo.Student" >
            <selectKey keyColumn="id" keyProperty="id" resultType="java.lang.Long" order="BEFORE">
                select student_seq.nextval as id from dual
            </selectKey>
            insert into student(<include refid="key"></include>) values (<include refid="values"></include>)
        </insert>
        
        <delete id="dynaDeleteArray" >
            delete student where id in
            <foreach collection="array" open="(" close=")" separator="," item="ids">
                #{ids}
            </foreach>
        </delete>
        
        <delete id="dynaDeleteList">
            delete from students where students_id in
            <foreach collection="list" open="(" close=")" separator="," item="ids">
                #{ids}
            </foreach>
        </delete>
        
        <update id="dynaUpdate" parameterType="com.oracle.pojo.Student">
            update student
            <set>
                <if test="address !=null">
                    address = #{address},
                </if>
                <if test="age!=0">
                    age = #{age},            
                </if>
            </set>
            where id=#{id}
        </update>
  • 相关阅读:
    计算机视觉--语义分割
    对团队成员公开感谢
    韩昊20191031-1 每周例行报告
    韩昊20191024-1 每周例行报告
    韩昊20191017-1 每周例行报告
    TensorFlow在windows 下的安装
    20191010-2 每周例行报告
    韩昊 20190919-1 每周例行报告
    韩昊 20190919-4 单元测试,结对
    2505-springboot使用spring.profiles.active来分区配置
  • 原文地址:https://www.cnblogs.com/Damon-Luo/p/5665005.html
Copyright © 2011-2022 走看看