<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fjs.scenic.mapper.news.NewsMapper">
	<resultMap id="BaseResultMap" type="com.fjs.scenic.entity.news.News">
		<id column="id" jdbcType="INTEGER" property="id" />
		<result column="title" jdbcType="VARCHAR" property="title" />
		<result column="time" jdbcType="TIMESTAMP" property="time" />
		<result column="mid" jdbcType="INTEGER" property="mid" />
		<result column="icon" jdbcType="VARCHAR" property="icon" />
		<result column="status" jdbcType="TINYINT" property="status" />
	</resultMap>
	<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs"
		type="com.fjs.scenic.entity.news.News">
		<result column="content" jdbcType="LONGVARCHAR" property="content" />
	</resultMap>

	<sql id="Base_Column_List">
		id, title, time, mid, icon, status
	</sql>
	<sql id="Blob_Column_List">
		content
	</sql>
	<insert id="insert" parameterType="com.fjs.scenic.entity.news.News">
		insert into news (id, title, time,
		mid, icon, status,
		content)
		values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR},
		#{time,jdbcType=TIMESTAMP},
		#{mid,jdbcType=INTEGER}, #{icon,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT},
		#{content,jdbcType=LONGVARCHAR})
	</insert>

	<update id="update" parameterType="com.fjs.scenic.entity.news.News">
		update news
		<set>
			<if test="title != null">
				title = #{title,jdbcType=VARCHAR},
			</if>
			<if test="time != null">
				time = #{time,jdbcType=TIMESTAMP},
			</if>
			<if test="mid != null">
				mid = #{mid,jdbcType=INTEGER},
			</if>
			<if test="icon != null">
				icon = #{icon,jdbcType=VARCHAR},
			</if>
			<if test="status != null">
				status = #{status,jdbcType=TINYINT},
			</if>
			<if test="content != null">
				content = #{content,jdbcType=LONGVARCHAR},
			</if>
		</set>
		where id = #{id,jdbcType=INTEGER}
	</update>

	<delete id="delete" parameterType="com.fjs.scenic.entity.news.News">
		delete from news where 1=1
		<if test="id != null"> and id = #{id}</if>
		<if test="title != null">
			and title = #{title,jdbcType=VARCHAR}
		</if>
		<if test="time != null">
			and time = #{time,jdbcType=TIMESTAMP},
		</if>
		<if test="mid != null">
			and mid = #{mid,jdbcType=INTEGER},
		</if>
		<if test="icon != null">
			and icon = #{icon,jdbcType=VARCHAR},
		</if>
		<if test="status != null">
			and status = #{status,jdbcType=TINYINT},
		</if>
		<if test="content != null">
			and content = #{content,jdbcType=LONGVARCHAR},
		</if>
	</delete>

	<select id="select" resultMap="BaseResultMap" parameterType="com.fjs.scenic.entity.news.News">
		select * from news where 1 = 1
		<if test="id != null"> and id = #{id}</if>
		<if test="title != null">

			and title like CONCAT(CONCAT('%', #{title,jdbcType=VARCHAR}), '%')
		</if>
		<if test="time != null">
			and time = #{time,jdbcType=TIMESTAMP}
		</if>
		<if test="mid != null">
			and mid = #{mid,jdbcType=INTEGER}
		</if>
		<if test="icon != null">
			and icon = #{icon,jdbcType=VARCHAR}
		</if>
		<if test="status != null">
			and status = #{status,jdbcType=TINYINT}
		</if>
		<if test="content != null">
			and content = #{content,jdbcType=LONGVARCHAR}
		</if>
		<if test="param != null">
			and #{param}
		</if>
		order by time desc 
	</select>

	<select id="selectByParam" resultMap="BaseResultMap"
		parameterType="java.util.Map">
		select
		<if test="field != null and field != ''"> ${field}</if>
		<if test="field == null or field == ''"> * </if>
		from news
		<if test="param != null and param != ''">where ${param}</if>
	</select>

	<delete id="deleteByParam" parameterType="java.util.Map">
		delete from news
		<if test="param != null and param != ''">where ${param}</if>
	</delete>

	<update id="updateByParam" parameterType="java.util.Map">
		<if test="param != null and param !=''">update news set ${param}</if>
	</update>
	
	<select id="getNewsLimt3" resultType="java.lang.String">
	SELECT title FROM news ORDER BY time DESC LIMIT 3
	</select>
</mapper>