NewsMapper.xml 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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.xc.dao.NewsMapper">
  4. <resultMap id="BaseResultMap" type="com.xc.pojo.News">
  5. <constructor>
  6. <idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer"/>
  7. <arg column="title" jdbcType="VARCHAR" javaType="java.lang.String"/>
  8. <arg column="cover" jdbcType="VARCHAR" javaType="java.lang.String"/>
  9. <arg column="content" jdbcType="VARCHAR" javaType="java.lang.String"/>
  10. <arg column="source" jdbcType="VARCHAR" javaType="java.lang.String"/>
  11. <arg column="hot" jdbcType="INTEGER" javaType="java.lang.Integer"/>
  12. <arg column="publish_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
  13. <arg column="create_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
  14. <arg column="update_time" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
  15. </constructor>
  16. </resultMap>
  17. <sql id="Base_Column_List">
  18. id, title, cover, content, source, hot, publish_time, create_time, update_time
  19. </sql>
  20. <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
  21. select
  22. <include refid="Base_Column_List"/>
  23. from news
  24. where id = #{id,jdbcType=INTEGER}
  25. </select>
  26. <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
  27. delete from news
  28. where id = #{id,jdbcType=INTEGER}
  29. </delete>
  30. <insert id="insert" parameterType="com.xc.pojo.News">
  31. insert into news (
  32. title, cover, content, source, hot, publish_time, create_time
  33. )
  34. values (#{title,jdbcType=VARCHAR}, #{cover,jdbcType=VARCHAR},
  35. #{content,jdbcType=VARCHAR},#{source,jdbcType=VARCHAR},
  36. #{hot,jdbcType=INTEGER}, #{publishTime,jdbcType=TIMESTAMP}, now()
  37. )
  38. </insert>
  39. <update id="updateByPrimaryKeySelective" parameterType="com.xc.pojo.News">
  40. update news
  41. <set>
  42. <if test="title != null">
  43. title = #{title,jdbcType=VARCHAR},
  44. </if>
  45. <if test="cover != null">
  46. cover = #{cover,jdbcType=VARCHAR},
  47. </if>
  48. <if test="content != null">
  49. content = #{content,jdbcType=VARCHAR},
  50. </if>
  51. <if test="source != null">
  52. source = #{source,jdbcType=VARCHAR},
  53. </if>
  54. <if test="hot != null">
  55. hot = #{hot,jdbcType=INTEGER},
  56. </if>
  57. <if test="publishTime != null">
  58. publish_time = #{publishTime,jdbcType=TIMESTAMP},
  59. </if>
  60. </set>
  61. where id = #{id,jdbcType=INTEGER}
  62. </update>
  63. <select id="listByNews" parameterType="map" resultMap="BaseResultMap">
  64. SELECT
  65. <include refid="Base_Column_List"/>
  66. FROM news
  67. <where>
  68. <if test="title != null and title != '' ">
  69. and title like CONCAT('%',#{title},'%')
  70. </if>
  71. <if test="source != null and source != '' ">
  72. and source like CONCAT('%',#{source},'%')
  73. </if>
  74. <if test="hot != null">
  75. and hot = #{hot}
  76. </if>
  77. </where>
  78. order by
  79. id
  80. desc
  81. </select>
  82. </mapper>