zoukankan      html  css  js  c++  java
  • 增删改查的比较好的写法

    1、增加

    <insert id="insertInfo" parameterType="drivercar">
    insert into t_drivers_cars
    <trim prefix="(" suffix=")" suffixOverrides=",">
    <if test="id !=null" >id,</if>
    <if test="driverId !=null">driverId,</if>
    <if test="carNum !=null" >carNum,</if>
    <if test="carTypeId !=null">carTypeId,</if>
    <if test="carLengthId !=null">carLengthId,</if>
    <if test="loadWeight !=null">loadWeight,</if>
    <if test="createTime !=null">createTime,</if>
    <if test="isDefault !=null">isDefault,</if>
    <if test="createDriverId !=null">createDriverId,</if>
    <if test="state !=null">state,</if>
    <if test="verificationErrorDesc !=null">verificationErrorDesc,</if>
    <if test="travelLicenseId !=null">travelLicenseId,</if>
    <if test="travelLicenseId_fan !=null">travelLicenseId_fan,</if>
    <if test="postType !=null">postType</if>
    </trim>
    <trim prefix="values(" suffix=")" suffixOverrides="">
    <if test="id !=null">#{id},</if>
    <if test="driverId !=null">#{driverId},</if>
    <if test="carNum !=null">#{carNum},</if>
    <if test="carTypeId !=null">#{carTypeId},</if>
    <if test="carLengthId !=null">#{carLengthId},</if>
    <if test="loadWeight !=null">#{loadWeight},</if>
    <if test="createTime !=null">#{createTime},</if>
    <if test="isDefault !=null">#{isDefault},</if>
    <if test="createDriverId !=null">#{createDriverId},</if>
    <if test="state !=null">#{state},</if>
    <if test="verificationErrorDesc !=null">#{verificationErrorDesc},</if>
    <if test="travelLicenseId !=null">#{travelLicenseId},</if>
    <if test="travelLicenseId_fan !=null">#{travelLicenseId_fan},</if>
    <if test="postType !=null">#{postType}</if>
    </trim>
    </insert>

    2、删除

    <delete id="deleteInfo" parameterType="drivercar">
    delete from t_drivers_cars where id=#{id}
    </delete>

    3、修改

    <update id="updateInfo" parameterType="drivercar">
    update t_drivers_cars
    <set>
    <if test="driverId !=null">driverId = #{driverId},</if>
    <if test="carNum!=null">carNum = #{carNum},</if>
    <if test="carTypeId!=null">carTypeId = #{carTypeId},</if>
    <if test="carLengthId!=null">carLengthId = #{carLengthId},</if>
    <if test="loadWeight!=null">loadWeight = #{loadWeight},</if>
    <if test="createTime!=null">createTime = #{createTime},</if>
    <if test="isDefault!=null">isDefault = #{isDefault},</if>
    <if test="verificationErrorDesc !=null">verificationErrorDesc = #{verificationErrorDesc},</if>
    <if test="createDriverId !=null">createDriverId = #{createDriverId},</if>
    <if test="travelLicenseId !=null">travelLicenseId = #{travelLicenseId},</if>
    <if test="travelLicenseId_fan !=null">travelLicenseId_fan = #{travelLicenseId_fan},</if>
    <if test="postType !=null">postType = #{postType},</if>
    <if test="state !=null">state = #{state},</if>
    <if test="isDel !=null">isDel = #{isDel}</if>
    </set>
    where id = #{id}
    </update>

    4、查询

    <select id="getCount" parameterType="java.util.HashMap" resultType="Integer">
    select count(1) from t_drivers_cars
    <where>
    <if test="states != null">
    <foreach collection="states" item="state" open="(" close=")" separator="or">
    state=#{state}
    </foreach>
    </if>
    <if test="carNum != null">and carNum like '%${carNum}%'</if>
    <if test="userName != null">and userName like '%${userName}%'</if>
    </where>
    </select>

    以上基本的增删改查这样写的话是比较严谨的

  • 相关阅读:
    python json 和 pickle的补充 hashlib configparser logging
    go 流程语句 if goto for swich
    go array slice map make new操作
    go 基础
    块级元素 行内元素 空元素
    咽炎就医用药(慢性肥厚性咽炎)
    春季感冒是风寒还是风热(转的文章)
    秋季感冒 咳嗽 怎么选药
    解决IE浏览器“无法显示此网页”的问题
    常用的 css 样式 记录
  • 原文地址:https://www.cnblogs.com/haoxiu1004/p/9680292.html
Copyright © 2011-2022 走看看