CRM项目优化XML配置的SQL语句解决AOP切面拼接查询语句导致的SQL语句错误问题------CRM项目

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.alatus.mapper.TActivityRemarkMapper">
  <resultMap id="BaseResultMap" type="com.alatus.model.TActivityRemark">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="activity_id" jdbcType="INTEGER" property="activityId" />
    <result column="note_content" jdbcType="VARCHAR" property="noteContent" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="deleted" jdbcType="INTEGER" property="deleted" />
  </resultMap>

  <resultMap id="ActivityRemarkResultMap" type="com.alatus.model.TActivityRemark">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="activity_id" jdbcType="INTEGER" property="activityId" />
    <result column="note_content" jdbcType="VARCHAR" property="noteContent" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="deleted" jdbcType="INTEGER" property="deleted" />
    <association property="createByDO" javaType="com.alatus.model.TUser">
      <id column="createId" jdbcType="INTEGER" property="id" />
      <result column="createName" jdbcType="VARCHAR" property="name" />
    </association>
    <association property="editByDO" javaType="com.alatus.model.TUser">
      <id column="editId" jdbcType="INTEGER" property="id" />
      <result column="editName" jdbcType="VARCHAR" property="name" />
    </association>
  </resultMap>

  <sql id="Base_Column_List">
    id, activity_id, note_content, create_time, create_by, edit_time, edit_by, deleted
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_activity_remark
    where id = #{id,jdbcType=INTEGER}
  </select>


    <select id="selectActivityRemarkByPage" resultMap="ActivityRemarkResultMap">
      select
        tar.*,
        tu1.id createId,tu1.name createName,
        tu2.id editId,tu2.name editName
      from t_activity_remark tar left join t_user tu1 on tar.create_by = tu1.id
                                left join t_user tu2 on tar.edit_by = tu2.id
      <where>
        tar.activity_id = #{activityId,jdbcType=INTEGER}
        ${filterSQL}
      </where>
    </select>


    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_activity_remark
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TActivityRemark" useGeneratedKeys="true">
    insert into t_activity_remark (activity_id, note_content, create_time,
      create_by, edit_time, edit_by, 
      deleted)
    values (#{activityId,jdbcType=INTEGER}, #{noteContent,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{createBy,jdbcType=INTEGER}, #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}, 
      #{deleted,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TActivityRemark" useGeneratedKeys="true">
    insert into t_activity_remark
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="activityId != null">
        activity_id,
      </if>
      <if test="noteContent != null">
        note_content,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="editTime != null">
        edit_time,
      </if>
      <if test="editBy != null">
        edit_by,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="activityId != null">
        #{activityId,jdbcType=INTEGER},
      </if>
      <if test="noteContent != null">
        #{noteContent,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        #{editBy,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.alatus.model.TActivityRemark">
    update t_activity_remark
    <set>
      <if test="activityId != null">
        activity_id = #{activityId,jdbcType=INTEGER},
      </if>
      <if test="noteContent != null">
        note_content = #{noteContent,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        edit_time = #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        edit_by = #{editBy,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        deleted = #{deleted,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.alatus.model.TActivityRemark">
    update t_activity_remark
    set activity_id = #{activityId,jdbcType=INTEGER},
      note_content = #{noteContent,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=INTEGER},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      edit_by = #{editBy,jdbcType=INTEGER},
      deleted = #{deleted,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.alatus.mapper.TActivityRemarkMapper">
  <resultMap id="BaseResultMap" type="com.alatus.model.TActivityRemark">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="activity_id" jdbcType="INTEGER" property="activityId" />
    <result column="note_content" jdbcType="VARCHAR" property="noteContent" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="deleted" jdbcType="INTEGER" property="deleted" />
  </resultMap>

  <resultMap id="ActivityRemarkResultMap" type="com.alatus.model.TActivityRemark">
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="activity_id" jdbcType="INTEGER" property="activityId" />
    <result column="note_content" jdbcType="VARCHAR" property="noteContent" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="create_by" jdbcType="INTEGER" property="createBy" />
    <result column="edit_time" jdbcType="TIMESTAMP" property="editTime" />
    <result column="edit_by" jdbcType="INTEGER" property="editBy" />
    <result column="deleted" jdbcType="INTEGER" property="deleted" />
    <association property="createByDO" javaType="com.alatus.model.TUser">
      <id column="createId" jdbcType="INTEGER" property="id" />
      <result column="createName" jdbcType="VARCHAR" property="name" />
    </association>
    <association property="editByDO" javaType="com.alatus.model.TUser">
      <id column="editId" jdbcType="INTEGER" property="id" />
      <result column="editName" jdbcType="VARCHAR" property="name" />
    </association>
  </resultMap>

  <sql id="Base_Column_List">
    id, activity_id, note_content, create_time, create_by, edit_time, edit_by, deleted
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from t_activity_remark
    where id = #{id,jdbcType=INTEGER}
  </select>


    <select id="selectActivityRemarkByPage" resultMap="ActivityRemarkResultMap">
      select
        tar.*,
        tu1.id createId,tu1.name createName,
        tu2.id editId,tu2.name editName
      from t_activity_remark tar left join t_user tu1 on tar.create_by = tu1.id
                                left join t_user tu2 on tar.edit_by = tu2.id
      <where>
        tar.activity_id = #{activityId,jdbcType=INTEGER}
        ${filterSQL}
      </where>
    </select>


    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from t_activity_remark
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TActivityRemark" useGeneratedKeys="true">
    insert into t_activity_remark (activity_id, note_content, create_time,
      create_by, edit_time, edit_by, 
      deleted)
    values (#{activityId,jdbcType=INTEGER}, #{noteContent,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP}, 
      #{createBy,jdbcType=INTEGER}, #{editTime,jdbcType=TIMESTAMP}, #{editBy,jdbcType=INTEGER}, 
      #{deleted,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.alatus.model.TActivityRemark" useGeneratedKeys="true">
    insert into t_activity_remark
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="activityId != null">
        activity_id,
      </if>
      <if test="noteContent != null">
        note_content,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="createBy != null">
        create_by,
      </if>
      <if test="editTime != null">
        edit_time,
      </if>
      <if test="editBy != null">
        edit_by,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="activityId != null">
        #{activityId,jdbcType=INTEGER},
      </if>
      <if test="noteContent != null">
        #{noteContent,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        #{editBy,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.alatus.model.TActivityRemark">
    update t_activity_remark
    <set>
      <if test="activityId != null">
        activity_id = #{activityId,jdbcType=INTEGER},
      </if>
      <if test="noteContent != null">
        note_content = #{noteContent,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="createBy != null">
        create_by = #{createBy,jdbcType=INTEGER},
      </if>
      <if test="editTime != null">
        edit_time = #{editTime,jdbcType=TIMESTAMP},
      </if>
      <if test="editBy != null">
        edit_by = #{editBy,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        deleted = #{deleted,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.alatus.model.TActivityRemark">
    update t_activity_remark
    set activity_id = #{activityId,jdbcType=INTEGER},
      note_content = #{noteContent,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      create_by = #{createBy,jdbcType=INTEGER},
      edit_time = #{editTime,jdbcType=TIMESTAMP},
      edit_by = #{editBy,jdbcType=INTEGER},
      deleted = #{deleted,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
</mapper>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值