NewsMapper.xml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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.kede.common.dao.NewsMapper">
  4. <resultMap id="BaseResultMap" type="com.kede.common.model.News">
  5. <id column="id" jdbcType="INTEGER" property="id" />
  6. <result column="title" jdbcType="VARCHAR" property="title" />
  7. <result column="publisher" jdbcType="VARCHAR" property="publisher" />
  8. <result column="type" jdbcType="INTEGER" property="type" />
  9. <result column="picture_url" jdbcType="VARCHAR" property="pictureUrl" />
  10. <result column="status" jdbcType="INTEGER" property="status" />
  11. <result column="sort" jdbcType="INTEGER" property="sort" />
  12. <result column="content" jdbcType="VARCHAR" property="content" />
  13. <result column="release_status" jdbcType="INTEGER" property="releaseStatus" />
  14. <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
  15. <result column="release_time" jdbcType="TIMESTAMP" property="releaseTime" />
  16. <result column="keywords" jdbcType="VARCHAR" property="keywords" />
  17. <result column="hot" jdbcType="BIGINT" property="hot" />
  18. </resultMap>
  19. <sql id="Base_Column_List">
  20. id, title, publisher, `type`, picture_url, `status`, sort, content, release_status,
  21. create_time, release_time, keywords, hot
  22. </sql>
  23. <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
  24. select
  25. <include refid="Base_Column_List" />
  26. from news
  27. where id = #{id,jdbcType=INTEGER}
  28. </select>
  29. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  30. delete from news
  31. where id = #{id,jdbcType=INTEGER}
  32. </delete>
  33. <insert id="insert" keyColumn="id" keyProperty="id" parameterType="com.kede.common.model.News" useGeneratedKeys="true">
  34. insert into news (title, publisher, `type`,
  35. picture_url, `status`, sort,
  36. content, release_status, create_time,
  37. release_time, keywords, hot
  38. )
  39. values (#{title,jdbcType=VARCHAR}, #{publisher,jdbcType=VARCHAR}, #{type,jdbcType=INTEGER},
  40. #{pictureUrl,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{sort,jdbcType=INTEGER},
  41. #{content,jdbcType=VARCHAR}, #{releaseStatus,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP},
  42. #{releaseTime,jdbcType=TIMESTAMP}, #{keywords,jdbcType=VARCHAR}, #{hot,jdbcType=BIGINT}
  43. )
  44. </insert>
  45. <insert id="insertSelective" keyColumn="id" keyProperty="id" parameterType="com.kede.common.model.News" useGeneratedKeys="true">
  46. insert into news
  47. <trim prefix="(" suffix=")" suffixOverrides=",">
  48. <if test="title != null">
  49. title,
  50. </if>
  51. <if test="publisher != null">
  52. publisher,
  53. </if>
  54. <if test="type != null">
  55. `type`,
  56. </if>
  57. <if test="pictureUrl != null">
  58. picture_url,
  59. </if>
  60. <if test="status != null">
  61. `status`,
  62. </if>
  63. <if test="sort != null">
  64. sort,
  65. </if>
  66. <if test="content != null">
  67. content,
  68. </if>
  69. <if test="releaseStatus != null">
  70. release_status,
  71. </if>
  72. <if test="createTime != null">
  73. create_time,
  74. </if>
  75. <if test="releaseTime != null">
  76. release_time,
  77. </if>
  78. <if test="keywords != null">
  79. keywords,
  80. </if>
  81. <if test="hot != null">
  82. hot,
  83. </if>
  84. </trim>
  85. <trim prefix="values (" suffix=")" suffixOverrides=",">
  86. <if test="title != null">
  87. #{title,jdbcType=VARCHAR},
  88. </if>
  89. <if test="publisher != null">
  90. #{publisher,jdbcType=VARCHAR},
  91. </if>
  92. <if test="type != null">
  93. #{type,jdbcType=INTEGER},
  94. </if>
  95. <if test="pictureUrl != null">
  96. #{pictureUrl,jdbcType=VARCHAR},
  97. </if>
  98. <if test="status != null">
  99. #{status,jdbcType=INTEGER},
  100. </if>
  101. <if test="sort != null">
  102. #{sort,jdbcType=INTEGER},
  103. </if>
  104. <if test="content != null">
  105. #{content,jdbcType=VARCHAR},
  106. </if>
  107. <if test="releaseStatus != null">
  108. #{releaseStatus,jdbcType=INTEGER},
  109. </if>
  110. <if test="createTime != null">
  111. #{createTime,jdbcType=TIMESTAMP},
  112. </if>
  113. <if test="releaseTime != null">
  114. #{releaseTime,jdbcType=TIMESTAMP},
  115. </if>
  116. <if test="keywords != null">
  117. #{keywords,jdbcType=VARCHAR},
  118. </if>
  119. <if test="hot != null">
  120. #{hot,jdbcType=BIGINT},
  121. </if>
  122. </trim>
  123. </insert>
  124. <update id="updateByPrimaryKeySelective" parameterType="com.kede.common.model.News">
  125. update news
  126. <set>
  127. <if test="title != null">
  128. title = #{title,jdbcType=VARCHAR},
  129. </if>
  130. <if test="publisher != null">
  131. publisher = #{publisher,jdbcType=VARCHAR},
  132. </if>
  133. <if test="type != null">
  134. `type` = #{type,jdbcType=INTEGER},
  135. </if>
  136. <if test="pictureUrl != null">
  137. picture_url = #{pictureUrl,jdbcType=VARCHAR},
  138. </if>
  139. <if test="status != null">
  140. `status` = #{status,jdbcType=INTEGER},
  141. </if>
  142. <if test="sort != null">
  143. sort = #{sort,jdbcType=INTEGER},
  144. </if>
  145. <if test="content != null">
  146. content = #{content,jdbcType=VARCHAR},
  147. </if>
  148. <if test="releaseStatus != null">
  149. release_status = #{releaseStatus,jdbcType=INTEGER},
  150. </if>
  151. <if test="createTime != null">
  152. create_time = #{createTime,jdbcType=TIMESTAMP},
  153. </if>
  154. <if test="releaseTime != null">
  155. release_time = #{releaseTime,jdbcType=TIMESTAMP},
  156. </if>
  157. <if test="keywords != null">
  158. keywords = #{keywords,jdbcType=VARCHAR},
  159. </if>
  160. <if test="hot != null">
  161. hot = #{hot,jdbcType=BIGINT},
  162. </if>
  163. </set>
  164. where id = #{id,jdbcType=INTEGER}
  165. </update>
  166. <update id="updateByPrimaryKey" parameterType="com.kede.common.model.News">
  167. update news
  168. set title = #{title,jdbcType=VARCHAR},
  169. publisher = #{publisher,jdbcType=VARCHAR},
  170. `type` = #{type,jdbcType=INTEGER},
  171. picture_url = #{pictureUrl,jdbcType=VARCHAR},
  172. `status` = #{status,jdbcType=INTEGER},
  173. sort = #{sort,jdbcType=INTEGER},
  174. content = #{content,jdbcType=VARCHAR},
  175. release_status = #{releaseStatus,jdbcType=INTEGER},
  176. create_time = #{createTime,jdbcType=TIMESTAMP},
  177. release_time = #{releaseTime,jdbcType=TIMESTAMP},
  178. keywords = #{keywords,jdbcType=VARCHAR},
  179. hot = #{hot,jdbcType=BIGINT}
  180. where id = #{id,jdbcType=INTEGER}
  181. </update>
  182. <select id="selectByid" resultType="com.kede.news.bo.OutNews">
  183. select id, title, publisher, type, picture_url pictureUrl, status, sort, release_status releaseStatus,content,
  184. date_format(create_time,'%Y-%m-%d %H:%i:%S') as createTimeConvert,create_time createTime,keywords,hot,
  185. date_format(release_time,'%Y-%m-%d %H:%i:%S') as releaseTimeConvert ,release_time releaseTime
  186. from news where id = #{id,jdbcType=INTEGER}
  187. </select>
  188. <select id="findNewsList" resultType="com.kede.news.bo.OutNews">
  189. select id, title, publisher, type, picture_url pictureUrl, status, sort, release_status releaseStatus,content,
  190. date_format(create_time,'%Y-%m-%d %H:%i:%S') as createTimeConvert,create_time createTime,hot,keywords,
  191. date_format(release_time,'%Y-%m-%d %H:%i:%S') as releaseTimeConvert ,release_time releaseTime
  192. from news where 1=1
  193. <if test="n.id!=null">
  194. and id = #{n.id}
  195. </if>
  196. <if test="n.title!=null">
  197. and title like concat('%',#{n.title},'%')
  198. </if>
  199. <if test="n.releaseStatus!=null">
  200. and release_status = #{n.releaseStatus}
  201. </if>
  202. <if test="n.status!=null">
  203. and status = #{n.status}
  204. </if>
  205. <if test="n.type!=null">
  206. and type = #{n.type}
  207. </if>
  208. order by
  209. <if test="n.hot ==1">
  210. hot desc,
  211. </if>
  212. release_time desc,sort desc
  213. <if test="page_sql!=null">
  214. ${page_sql}
  215. </if>
  216. </select>
  217. <select id="findNewsCount" resultType="java.lang.Integer">
  218. select count(*)
  219. from news where 1=1
  220. <if test="n.id!=null">
  221. and id = #{n.id}
  222. </if>
  223. <if test="n.title!=null">
  224. and title like concat('%',#{n.title},'%')
  225. </if>
  226. <if test="n.releaseStatus!=null">
  227. and release_status = #{n.releaseStatus}
  228. </if>
  229. <if test="n.status!=null">
  230. and status = #{n.status}
  231. </if>
  232. <if test="n.type!=null">
  233. and type = #{n.type}
  234. </if>
  235. </select>
  236. </mapper>