美文网首页
mybatis的xml中,时间怎么直接在xml中获取

mybatis的xml中,时间怎么直接在xml中获取

作者: 墨色尘埃 | 来源:发表于2017-12-17 15:41 被阅读26次

比如操作一条数据需要记录操作时间,而接口文档规定传递的参数并没有时间,该怎么做呢?不需要后台传递过来,那么也可以直接在xml中获取,使用now()。
先看update更新语句

<update id="updateByPrimaryKeySelective" parameterType="com.jsptpd.gayg.modules.business.model.FollowBusiInfo">
        update t_follow_business
        <set>
            OPERATE_TIME = now(),
            <if test="busiCategory != null">
                BUSI_CATEGORY = #{busiCategory,jdbcType=VARCHAR},
            </if>
            <if test="busiBrand != null">
                BUSI_BRAND = #{busiBrand,jdbcType=VARCHAR},
            </if>
            <if test="regCapital != null">
                REG_CAPITAL = #{regCapital,jdbcType=DECIMAL},
            </if>
            <if test="agenLevel != null">
                AGEN_LEVEL = #{agenLevel,jdbcType=VARCHAR},
            </if>
            <if test="conPerson != null">
                CON_PERSON = #{conPerson,jdbcType=VARCHAR},
            </if>
            <if test="conPhone != null">
                CON_PHONE = #{conPhone,jdbcType=VARCHAR},
            </if>
            <if test="areaPos != null">
                AREA_POS = #{areaPos,jdbcType=VARCHAR},
            </if>
            <if test="enterDate != null">
                ENTER_DATE = #{enterDate,jdbcType=DATE},
            </if>
            <if test="followPerson != null">
                FOLLOW_PERSON = #{followPerson,jdbcType=VARCHAR},
            </if>
            <if test="followCase != null">
                FOLLOW_CASE = #{followCase,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                STATUS = #{status,jdbcType=INTEGER},
            </if>
            <if test="operator != null">
                OPERATOR = #{operator,jdbcType=VARCHAR},
            </if>
        </set>
        where BUSINESS_ID = #{businessId,jdbcType=VARCHAR} AND STATUS=101001;
    </update>
    <update id="updateByPrimaryKey" parameterType="com.jsptpd.gayg.modules.business.model.FollowBusiInfo">
    update t_follow_business
    set BUSI_CATEGORY = #{busiCategory,jdbcType=VARCHAR},
      BUSI_BRAND = #{busiBrand,jdbcType=VARCHAR},
      REG_CAPITAL = #{regCapital,jdbcType=DECIMAL},
      AGEN_LEVEL = #{agenLevel,jdbcType=VARCHAR},
      CON_PERSON = #{conPerson,jdbcType=VARCHAR},
      CON_PHONE = #{conPhone,jdbcType=VARCHAR},
      AREA_POS = #{areaPos,jdbcType=VARCHAR},
      ENTER_DATE = #{enterDate,jdbcType=DATE},
      FOLLOW_PERSON = #{followPerson,jdbcType=VARCHAR},
      FOLLOW_CASE = #{followCase,jdbcType=VARCHAR},
      STATUS = #{status,jdbcType=INTEGER},
      OPERATOR = #{operator,jdbcType=VARCHAR},
      OPERATE_TIME = now()
    where BUSINESS_ID = #{businessId,jdbcType=VARCHAR} AND STATUS=101001;
  </update>

插入语句

<insert id="insertSelective" parameterType="com.jsptpd.gayg.modules.business.model.FollowBusiInfo">
        insert into t_follow_business
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="businessId != null">
                BUSINESS_ID,
            </if>
            <if test="busiCategory != null">
                BUSI_CATEGORY,
            </if>
            <if test="busiBrand != null">
                BUSI_BRAND,
            </if>
            <if test="regCapital != null">
                REG_CAPITAL,
            </if>
            <if test="agenLevel != null">
                AGEN_LEVEL,
            </if>
            <if test="conPerson != null">
                CON_PERSON,
            </if>
            <if test="conPhone != null">
                CON_PHONE,
            </if>
            <if test="areaPos != null">
                AREA_POS,
            </if>
            <if test="enterDate != null">
                ENTER_DATE,
            </if>
            <if test="followPerson != null">
                FOLLOW_PERSON,
            </if>
            <if test="followCase != null">
                FOLLOW_CASE,
            </if>
            <if test="status != null">
                STATUS,
            </if>
            <if test="operator != null">
                OPERATOR,
            </if>
                OPERATE_TIME
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="businessId != null">
                #{businessId,jdbcType=VARCHAR},
            </if>
            <if test="busiCategory != null">
                #{busiCategory,jdbcType=VARCHAR},
            </if>
            <if test="busiBrand != null">
                #{busiBrand,jdbcType=VARCHAR},
            </if>
            <if test="regCapital != null">
                #{regCapital,jdbcType=DECIMAL},
            </if>
            <if test="agenLevel != null">
                #{agenLevel,jdbcType=VARCHAR},
            </if>
            <if test="conPerson != null">
                #{conPerson,jdbcType=VARCHAR},
            </if>
            <if test="conPhone != null">
                #{conPhone,jdbcType=VARCHAR},
            </if>
            <if test="areaPos != null">
                #{areaPos,jdbcType=VARCHAR},
            </if>
            <if test="enterDate != null">
                #{enterDate,jdbcType=DATE},
            </if>
            <if test="followPerson != null">
                #{followPerson,jdbcType=VARCHAR},
            </if>
            <if test="followCase != null">
                #{followCase,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=INTEGER},
            </if>
            <if test="operator != null">
                #{operator,jdbcType=VARCHAR},
            </if>
                now()
        </trim>
    </insert>

思考:这条sql语句是查询表里符合条件的记录数

    <select id="countByRole" parameterType="java.util.Map" resultType="java.lang.Integer">
        select count(*)
        from t_follow_business
        <where>
            status=101001
        </where>
    </select>

相关文章

网友评论

      本文标题:mybatis的xml中,时间怎么直接在xml中获取

      本文链接:https://www.haomeiwen.com/subject/booywxtx.html