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>

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

  • 相关阅读:
    最全的“大数据”学习资源
    民生银行十五年的数据体系建设,深入解读阿拉丁大数据生态圈、人人BI 是如何养成的?【转】
    大数据分析界的“神兽”Apache Kylin有多牛?【转】
    大数据环境下互联网行业数据仓库/数据平台的架构之漫谈-续【转】
    写给大数据开发初学者的话5[转]
    唯品会海量实时OLAP分析技术升级之路
    大数据学习笔记
    元数据
    数据仓库之数据模型
    官方教程:Apache Kylin和Superset集成,使用开源组件,完美打造OLAP系统
  • 原文地址:https://www.cnblogs.com/haoxiu1004/p/9680292.html
Copyright © 2011-2022 走看看