1
0

CommonQuerySqlServerMapper.xml 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
  3. "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
  4. <mapper namespace="com.izouma.awesomeadmin.dao.CommonQuerySqlServerMapper">
  5. <select id="getTableListByPage" resultType="java.util.Map">
  6. SELECT * FROM ${record.tableName}
  7. <where>
  8. <if test="record.advancedQuery != null and !&quot;&quot;.equals(record.advancedQuery)">
  9. <foreach item="item" index="index" collection="record.advancedQuery.split('_;')">
  10. <choose>
  11. <when test="item.indexOf('like') != -1">
  12. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  13. <if test="detailIndex == 3">
  14. concat('%',#{itemDetail},'%')
  15. </if>
  16. <if test="detailIndex &lt; 3">
  17. ${itemDetail}
  18. </if>
  19. </foreach>
  20. </when>
  21. <when test="item.indexOf('in') != -1">
  22. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  23. <if test="detailIndex == 3">
  24. (${itemDetail})
  25. </if>
  26. <if test="detailIndex &lt; 3">
  27. ${itemDetail}
  28. </if>
  29. </foreach>
  30. </when>
  31. <otherwise>
  32. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  33. <if test="detailIndex == 3">
  34. #{itemDetail}
  35. </if>
  36. <if test="detailIndex &lt; 3">
  37. ${itemDetail}
  38. </if>
  39. </foreach>
  40. </otherwise>
  41. </choose>
  42. </foreach>
  43. </if>
  44. <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
  45. <trim prefix="and (" suffix=")" prefixOverrides="OR">
  46. <foreach item="item" index="index" collection="record.searchColumn.split('_,')">
  47. OR ${item} LIKE concat('%',#{record.searchKey},'%')
  48. </foreach>
  49. </trim>
  50. </if>
  51. </where>
  52. <if test="record.orderByStr != null and !&quot;&quot;.equals(record.orderByStr)">
  53. order by
  54. <trim suffixOverrides=",">
  55. <foreach item="item" index="index" separator="," collection="record.orderByStr.split('_;')">
  56. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  57. ${itemDetail}
  58. </foreach>
  59. </foreach>
  60. </trim>
  61. </if>
  62. </select>
  63. <select id="getTableListAll" resultType="java.util.Map">
  64. SELECT * FROM ${tableName}
  65. <where>
  66. <if test="advancedQuery != null and !&quot;&quot;.equals(advancedQuery)">
  67. <foreach item="item" index="index" collection="advancedQuery.split('_;')">
  68. <choose>
  69. <when test="item.indexOf('like') != -1">
  70. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  71. <if test="detailIndex == 3">
  72. concat('%',#{itemDetail},'%')
  73. </if>
  74. <if test="detailIndex &lt; 3">
  75. ${itemDetail}
  76. </if>
  77. </foreach>
  78. </when>
  79. <when test="item.indexOf('in') != -1">
  80. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  81. <if test="detailIndex == 3">
  82. (${itemDetail})
  83. </if>
  84. <if test="detailIndex &lt; 3">
  85. ${itemDetail}
  86. </if>
  87. </foreach>
  88. </when>
  89. <otherwise>
  90. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  91. <if test="detailIndex == 3">
  92. #{itemDetail}
  93. </if>
  94. <if test="detailIndex &lt; 3">
  95. ${itemDetail}
  96. </if>
  97. </foreach>
  98. </otherwise>
  99. </choose>
  100. </foreach>
  101. </if>
  102. <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
  103. <trim prefix="and (" suffix=")" prefixOverrides="OR">
  104. <foreach item="item" index="index" collection="searchColumn.split('_,')">
  105. OR ${item} LIKE concat('%',#{searchKey},'%')
  106. </foreach>
  107. </trim>
  108. </if>
  109. </where>
  110. <if test="orderByStr != null and !&quot;&quot;.equals(orderByStr)">
  111. order by
  112. <trim suffixOverrides=",">
  113. <foreach item="item" index="index" separator="," collection="orderByStr.split('_;')">
  114. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  115. ${itemDetail}
  116. </foreach>
  117. </foreach>
  118. </trim>
  119. </if>
  120. </select>
  121. <select id="selectByPrimaryKey" resultType="java.util.Map" parameterType="java.util.Map">
  122. select top 1
  123. *
  124. from ${tableName}
  125. <where>
  126. <if test="primaryKey != null and !&quot;&quot;.equals(primaryKey)">
  127. id = #{primaryKey,jdbcType=INTEGER}
  128. </if>
  129. <if test="advancedQuery != null and !&quot;&quot;.equals(advancedQuery)">
  130. <foreach item="item" index="index" collection="advancedQuery.split('_;')">
  131. <choose>
  132. <when test="item.indexOf('like') != -1">
  133. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  134. <if test="detailIndex == 3">
  135. concat('%',#{itemDetail},'%')
  136. </if>
  137. <if test="detailIndex &lt; 3">
  138. ${itemDetail}
  139. </if>
  140. </foreach>
  141. </when>
  142. <when test="item.indexOf('in') != -1">
  143. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  144. <if test="detailIndex == 3">
  145. (${itemDetail})
  146. </if>
  147. <if test="detailIndex &lt; 3">
  148. ${itemDetail}
  149. </if>
  150. </foreach>
  151. </when>
  152. <otherwise>
  153. <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
  154. <if test="detailIndex == 3">
  155. #{itemDetail}
  156. </if>
  157. <if test="detailIndex &lt; 3">
  158. ${itemDetail}
  159. </if>
  160. </foreach>
  161. </otherwise>
  162. </choose>
  163. </foreach>
  164. </if>
  165. </where>
  166. </select>
  167. <insert id="insertSelective" parameterType="java.util.Map" useGeneratedKeys="true"
  168. keyProperty="id">
  169. insert into ${tableName}
  170. <trim prefix="(" suffix=")" suffixOverrides=",">
  171. <foreach item="item" index="index" collection="formData.keys">
  172. <if test="formData[item]!= null">
  173. ${item},
  174. </if>
  175. </foreach>
  176. </trim>
  177. <trim prefix="values (" suffix=")" suffixOverrides=",">
  178. <foreach item="item" index="index" collection="formData.keys">
  179. <if test="formData[item]!= null">
  180. #{formData[${item}]},
  181. </if>
  182. </foreach>
  183. </trim>
  184. </insert>
  185. <update id="updateByPrimaryKeySelective" parameterType="java.util.Map">
  186. update ${tableName}
  187. <set>
  188. <foreach item="item" index="index" collection="formData.keys">
  189. <if test="formData[item]!= null">
  190. ${item} = #{formData[${item}]},
  191. </if>
  192. </foreach>
  193. </set>
  194. where id = #{primaryKey,jdbcType=INTEGER}
  195. </update>
  196. <delete id="delete">
  197. delete from ${tableName}
  198. where id = #{primaryKey,jdbcType=INTEGER}
  199. </delete>
  200. </mapper>