Demo.xml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  3. <mapper namespace="com.steerinfo.dil.logresult.mapper.LogResultMapper">
  4. <resultMap id="BaseResultMap" type="com.steerinfo.dil.logresult.model.LogResult">
  5. <id column="LOG_ID" jdbcType="DECIMAL" property="logId" />
  6. <result column="LOG_CONTENT" jdbcType="VARCHAR" property="logContent" />
  7. <result column="FOREIGN_KEY_ID" jdbcType="DECIMAL" property="foreignKeyId" />
  8. <result column="FOREIGN_KEY_TYPE" jdbcType="VARCHAR" property="foreignKeyType" />
  9. <result column="METHOD_NAME" jdbcType="VARCHAR" property="methodName" />
  10. <result column="METHOD_DESCRIPTION" jdbcType="VARCHAR" property="methodDescription" />
  11. <result column="EXE_COST" jdbcType="DECIMAL" property="exeCost" />
  12. <result column="FILE_PATH" jdbcType="VARCHAR" property="filePath" />
  13. <result column="INSERT_TIME" jdbcType="TIMESTAMP" property="insertTime" />
  14. <result column="INSERT_USERNAME" jdbcType="VARCHAR" property="insertUsername" />
  15. <result column="REMARK" jdbcType="VARCHAR" property="remark" />
  16. <result column="DATAGRAM1" jdbcType="VARCHAR" property="datagram1" />
  17. <result column="DATAGRAM2" jdbcType="VARCHAR" property="datagram2" />
  18. <result column="DATAGRAM3" jdbcType="VARCHAR" property="datagram3" />
  19. <result column="ALTERNATE_FIELDS1" jdbcType="VARCHAR" property="alternateFields1" />
  20. <result column="ALTERNATE_FIELDS2" jdbcType="VARCHAR" property="alternateFields2" />
  21. <result column="ALTERNATE_FIELDS3" jdbcType="VARCHAR" property="alternateFields3" />
  22. <result column="ALTERNATE_FIELDS4" jdbcType="VARCHAR" property="alternateFields4" />
  23. <result column="ALTERNATE_FIELDS5" jdbcType="VARCHAR" property="alternateFields5" />
  24. <result column="ALTERNATE_FIELDS6" jdbcType="VARCHAR" property="alternateFields6" />
  25. <result column="ALTERNATE_FIELDS7" jdbcType="VARCHAR" property="alternateFields7" />
  26. <result column="ALTERNATE_FIELDS8" jdbcType="VARCHAR" property="alternateFields8" />
  27. <result column="ALTERNATE_FIELDS9" jdbcType="VARCHAR" property="alternateFields9" />
  28. <result column="ALTERNATE_FIELDS10" jdbcType="VARCHAR" property="alternateFields10" />
  29. <result column="ALTERNATE_FIELDS11" jdbcType="VARCHAR" property="alternateFields11" />
  30. <result column="ALTERNATE_FIELDS12" jdbcType="VARCHAR" property="alternateFields12" />
  31. <result column="ALTERNATE_FIELDS13" jdbcType="VARCHAR" property="alternateFields13" />
  32. <result column="ALTERNATE_FIELDS14" jdbcType="VARCHAR" property="alternateFields14" />
  33. <result column="ALTERNATE_FIELDS15" jdbcType="VARCHAR" property="alternateFields15" />
  34. <result column="ALTERNATE_FIELDS16" jdbcType="VARCHAR" property="alternateFields16" />
  35. </resultMap>
  36. <sql id="columns">
  37. LOG_ID,LOG_CONTENT,FOREIGN_KEY_ID,FOREIGN_KEY_TYPE
  38. </sql>
  39. <sql id="select">
  40. select <include refid="columns"/> from log_result
  41. </sql>
  42. <!-- 1.定义重复的字段列表,维护成本高,通过复用基础字段来简化-->
  43. <sql id="aliasColumns">
  44. <foreach collection="columns.split(',')" item="col" separator=",">
  45. t.${col.trim()}
  46. </foreach>
  47. </sql>
  48. <sql id="select_alias">
  49. select <include refid="aliasColumns"> from log_result t</include>
  50. </sql>
  51. <sql id="where">
  52. <where>
  53. <if test="logId !=null">
  54. and LOG_ID=#{logId}
  55. </if>
  56. <if test="logContent !=null and logContent !=''">
  57. and LOG_CONTENT=#{logContent}
  58. </if>
  59. <if test="foreignKeyType !=null and foreignKeyType !=''">
  60. and FOREIGN_KEY_TYPE=#{foreignKeyType}
  61. </if>
  62. -- 2.重复字段的硬编译,用循环来优化
  63. <if test="alternateFeilds !=null and alternateFeilds.size()>0">
  64. <foreach collection="alternateFeilds" item="field" index="index">
  65. <if test="field !=null and field !=''">
  66. and ALTERNATE_FIELDS${index +1}=#{field}
  67. </if>
  68. </foreach>
  69. </if>
  70. </where>
  71. </sql>
  72. <sql id="whereLike">
  73. <where>
  74. <if test="logId !=null">
  75. and LOG_ID=#{logId}
  76. </if>
  77. <if test="logContent !=null and logContent !=''">
  78. -- 3.直接拼接会存在SQL注入的风险
  79. and LOG_CONTENT like concat('%',#{logContent},'%')
  80. </if>
  81. <if test="foreignKeyId !=null">
  82. and FOREIGN_KEY_ID=#{foreignKeyId}
  83. </if>
  84. <if test="foreignKeyType !=null and foreignKeyType !=''">
  85. and FOREIGN_KEY_TYPE like concat('%','foreignKeyType','%')
  86. </if>
  87. <if test="insertTime !=null">
  88. and TO_CHAR(INSERT_TIME,'yyyy-mm-dd')=#{insertTime}
  89. </if>
  90. <if test="datagram !=null and datagram !=''">
  91. <foreach collection="datagram" item="field" index="index">
  92. <if test="field !=null and field !=''">
  93. and DATAGRAM${index+1} like concat('%','field','%')
  94. </if>
  95. </foreach>
  96. </if>
  97. <if test="alternateFields !=null and alternateFields !=''">
  98. <foreach collection="alternateFields" item="field" index="index">
  99. <if test="field !=null and field !=''">
  100. and ALTERNATE_FIELDS${index+1} like concat('%','field','%')
  101. </if>
  102. </foreach>
  103. </if>
  104. </where>
  105. </sql>
  106. <delete id="deleteByPrimaryKey" parameterType="java.math.BigDecimal">
  107. delete from LOG_RESULT
  108. where LOG_ID=#{logId,jdbcType=DECIMAL}
  109. </delete>
  110. <delete id="delete" parameterType="HashMap">
  111. delete from LOG_RESULT
  112. where 1!=1
  113. <if test="logContent !=null and logContent !=''">
  114. or LOG_CONTENT=#{logContent}
  115. </if>
  116. <if test="datagram !=null and datagram !=''">
  117. <foreach collection="datagram" index="index" item="field">
  118. <if test="field !=null and field !=''">
  119. or DATAGRAM${index+1} =#{field}
  120. </if>
  121. </foreach>
  122. </if>
  123. </delete>
  124. <insert id="insert" parameterType="LogResult">
  125. insert into LOG_RESULT(LOG_ID,LOG_CONTENT,FOREIGN_KEY_ID,FOREIGN_KEY_TYPE)
  126. values(#{logId},#{logContent},#{foreignKeyId},#{foreignKeyType}})
  127. </insert>
  128. <insert id="insert2" parameterType="LogResult">
  129. insert into LOG_RESULT
  130. <trim prefix="(" suffix=")" suffixOverrides=",">
  131. <if test="logId !=null"> LOG_ID,</if>
  132. <if test="logContent !=null"> LOG_CONTENT,</if>
  133. <if test="foreignKeyId !=null"> FOREIGN_KEY_ID,</if>
  134. <if test="foreignKeyType !=null"> FOREIGN_KEY_TYPE,</if>
  135. <if test="alternateFields !=null">
  136. <foreach collection="alternateFields" item="field" index="index">
  137. ALTERNATE_FIELDS${index+1},
  138. </foreach>
  139. </if>
  140. </trim>
  141. <trim prefix="values (" suffix=")" suffixOverrides=",">
  142. <if test="logId !=null">#{logId}</if>
  143. <if test="logContent !=null">#{logContent}</if>
  144. <if test="foreignKeyId !=null">#{foreignKeyId}</if>
  145. <if test="foreignKeyType !=null">#{foreignKeyType}</if>
  146. <if test="alternateFields !=null">
  147. <foreach collection="alternateFields" index="index" item="field">
  148. <if test="field !=null">
  149. #{field}
  150. </if>
  151. </foreach>
  152. </if>
  153. </trim>
  154. </insert>
  155. <update id="update" parameterType="LogResult">
  156. update LOG_RESULT
  157. set LOG_CONTENT=#{logContent},
  158. FOREIGN_KEY_ID=#{foeignKeyId},
  159. FOREIGN_KEY_TYPE= #{foreignKeyType}
  160. where LOG_ID=#{logId}
  161. </update>
  162. <update id="update2" parameterType="LogResult">
  163. update LOG_RESULT
  164. <set>
  165. <if test="logContent !=null">
  166. LOG_CONTENT=#{logContent}
  167. </if>
  168. <if test="foreignKeyId !=null">
  169. FOREIGN_KEY_ID= #{foreignKeyId}
  170. </if>
  171. <if test="foreignKeyType !=null">
  172. FOREIGN_KEY_TYPE= #{foreignKeyType}
  173. </if>
  174. <if test="alternateFields !=null">
  175. <foreach collection="alternateFields" index="index" item="field">
  176. <if test="field !=null">
  177. ALTERNATE_FIELDS${index+1}=#{field}
  178. </if>
  179. </foreach>
  180. </if>
  181. </set>
  182. where LOG_ID = #{logId}
  183. </update>
  184. <!-- 4.分页查询添加分页查询支持-->
  185. <select id="selectByParameters" parameterType="HashMap" resultType="BaseResultMap">
  186. <include refid="select"></include>
  187. <include refid="where"></include>
  188. limit #{offset} , #{pageSize}
  189. </select>
  190. <delete id="batchDel" parameterType="List">
  191. delete from LOG_RESULT
  192. where LOG_ID in
  193. <foreach collection="list" item="id" open="(" close=")" separator=",">
  194. #{id}
  195. </foreach>
  196. </delete>
  197. </mapper>