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>

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

  • 相关阅读:
    Web前端开发中的各种CSS规范
    SVN简明课程
    使用django-compressor压缩静态文件
    今日头条视频Url嗅探
    python 异常类型
    抓包分析工具备注
    电子签章盖章之jQuery插件jquery.zsign
    程序员读书雷达
    在csdn里markdown感受
    如何在无趣的世界里,做一个有趣的人?
  • 原文地址:https://www.cnblogs.com/haoxiu1004/p/9680292.html
Copyright © 2011-2022 走看看