ArticleReadMapper.xml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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.slodon.b2b2c.dao.read.cms.ArticleReadMapper">
  4. <resultMap id="resultMap" type="com.slodon.b2b2c.cms.pojo.Article">
  5. <id column="article_id" property="articleId" />
  6. <result column="web_site" property="webSite" />
  7. <result column="category_id" property="categoryId" />
  8. <result column="title" property="title" />
  9. <result column="out_url" property="outUrl" />
  10. <result column="state" property="state" />
  11. <result column="sort" property="sort" />
  12. <result column="create_id" property="createId" />
  13. <result column="create_time" property="createTime" />
  14. <result column="update_time" property="updateTime" />
  15. <result column="content" property="content" />
  16. </resultMap>
  17. <!--按照主键值进行操作-->
  18. <sql id="pkWhere">
  19. WHERE `article_id` = #{primaryKey}
  20. </sql>
  21. <!--操作条件-->
  22. <sql id="whereCondition">
  23. <if test="example != null">
  24. <trim prefix="WHERE" prefixOverrides="AND|OR">
  25. <if test="example.articleIdNotEquals != null">
  26. AND `article_id` != #{example.articleIdNotEquals}
  27. </if>
  28. <if test="example.articleIdIn != null">
  29. AND `article_id` in (${example.articleIdIn})
  30. </if>
  31. <if test="example.webSite != null">
  32. AND `web_site` = #{example.webSite}
  33. </if>
  34. <if test="example.categoryId != null">
  35. AND `category_id` = #{example.categoryId}
  36. </if>
  37. <if test="example.title != null">
  38. AND `title` = #{example.title}
  39. </if>
  40. <if test="example.titleLike != null">
  41. AND `title` like concat('%',#{example.titleLike},'%')
  42. </if>
  43. <if test="example.outUrl != null">
  44. AND `out_url` = #{example.outUrl}
  45. </if>
  46. <if test="example.state != null">
  47. AND `state` = #{example.state}
  48. </if>
  49. <if test="example.sort != null">
  50. AND `sort` = #{example.sort}
  51. </if>
  52. <if test="example.createId != null">
  53. AND `create_id` = #{example.createId}
  54. </if>
  55. <if test="example.createTimeAfter != null">
  56. AND `create_time` <![CDATA[ >= ]]> #{example.createTimeAfter}
  57. </if>
  58. <if test="example.createTimeBefore != null">
  59. AND `create_time` <![CDATA[ <= ]]> #{example.createTimeBefore}
  60. </if>
  61. <if test="example.updateTimeAfter != null">
  62. AND `update_time` <![CDATA[ >= ]]> #{example.updateTimeAfter}
  63. </if>
  64. <if test="example.updateTimeBefore != null">
  65. AND `update_time` <![CDATA[ <= ]]> #{example.updateTimeBefore}
  66. </if>
  67. <if test="example.content != null">
  68. AND `content` = #{example.content}
  69. </if>
  70. <if test="example.contentLike != null">
  71. AND `content` like concat('%',#{example.contentLike},'%')
  72. </if>
  73. </trim>
  74. </if>
  75. </sql>
  76. <!--排序条件-->
  77. <sql id="orderBy">
  78. ORDER BY `article_id` DESC
  79. </sql>
  80. <sql id="orderByOther">
  81. order by ${example.orderBy}
  82. </sql>
  83. <!--分组条件-->
  84. <sql id="groupBy">
  85. group by ${example.groupBy}
  86. </sql>
  87. <!--分页条件-->
  88. <sql id="limit">
  89. <if test="size != null and size &gt; 0">
  90. limit #{startRow},#{size}
  91. </if>
  92. </sql>
  93. <!--查询符合条件的记录数-->
  94. <select id="countByExample" parameterType="com.slodon.b2b2c.cms.example.ArticleExample" resultType="java.lang.Integer">
  95. SELECT
  96. COUNT(*)
  97. FROM `cms_article`
  98. <include refid="whereCondition" />
  99. </select>
  100. <!--根据主键查询记录-->
  101. <select id="getByPrimaryKey" resultMap="resultMap">
  102. SELECT
  103. *
  104. FROM `cms_article`
  105. <include refid="pkWhere" />
  106. </select>
  107. <!--查询符合条件的记录(所有字段)-->
  108. <select id="listByExample" resultMap="resultMap">
  109. SELECT
  110. *
  111. FROM `cms_article`
  112. <include refid="whereCondition" />
  113. <if test="example.groupBy != null">
  114. <include refid="groupBy" />
  115. </if>
  116. <choose>
  117. <when test="example.orderBy != null">
  118. <include refid="orderByOther" />
  119. </when>
  120. <otherwise>
  121. <include refid="orderBy" />
  122. </otherwise>
  123. </choose>
  124. </select>
  125. <!--分页查询符合条件的记录(所有字段)-->
  126. <select id="listPageByExample" resultMap="resultMap">
  127. SELECT
  128. *
  129. FROM `cms_article`
  130. <include refid="whereCondition" />
  131. <if test="example.groupBy != null">
  132. <include refid="groupBy" />
  133. </if>
  134. <choose>
  135. <when test="example.orderBy != null">
  136. <include refid="orderByOther" />
  137. </when>
  138. <otherwise>
  139. <include refid="orderBy" />
  140. </otherwise>
  141. </choose>
  142. <include refid="limit" />
  143. </select>
  144. <!--查询符合条件的记录(指定字段)-->
  145. <select id="listFieldsByExample" resultMap="resultMap">
  146. SELECT
  147. ${fields}
  148. FROM `cms_article`
  149. <include refid="whereCondition" />
  150. <if test="example.groupBy != null">
  151. <include refid="groupBy" />
  152. </if>
  153. <choose>
  154. <when test="example.orderBy != null">
  155. <include refid="orderByOther" />
  156. </when>
  157. <otherwise>
  158. <include refid="orderBy" />
  159. </otherwise>
  160. </choose>
  161. </select>
  162. <!--分页查询符合条件的记录(指定字段)-->
  163. <select id="listFieldsPageByExample" resultMap="resultMap">
  164. SELECT
  165. ${fields}
  166. FROM `cms_article`
  167. <include refid="whereCondition" />
  168. <if test="example.groupBy != null">
  169. <include refid="groupBy" />
  170. </if>
  171. <choose>
  172. <when test="example.orderBy != null">
  173. <include refid="orderByOther" />
  174. </when>
  175. <otherwise>
  176. <include refid="orderBy" />
  177. </otherwise>
  178. </choose>
  179. <include refid="limit" />
  180. </select>
  181. </mapper>