<?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="cn.wisenergy.mapper.BannerMapper"> <resultMap id="advertisingMap" type="cn.wisenergy.model.app.Banner"> <id column="id" property="id"/> <result column="company_name" property="companyName"/> <result column="status" property="status"/> <result column="website" property="website"/> <result column="is_have_image" property="isHaveImage"/> <result column="type" property="type"/> <result column="image" property="image"/> <result column="create_time" property="createTime"/> <result column="update_time" property="updateTime"/> </resultMap> <sql id="table"> banner </sql> <sql id="cols_all"> id, <include refid="cols_exclude_id"/> </sql> <sql id="cols_exclude_id"> company_name,status, website,is_have_image,type,image, create_time,update_time </sql> <sql id="vals"> #{companyName},#{status},#{website},#{isHaveImage},#{type},#{image},now(),now() </sql> <sql id="updateCondition"> <if test="companyName != null">company_name = #{companyName},</if> <if test="status != null">status =#{status},</if> <if test="website != null">website =#{website},</if> <if test="isHaveImage != null">is_have_image =#{isHaveImage},</if> <if test="type != null">type =#{type},</if> <if test="image != null">image =#{image},</if> update_time =now() </sql> <sql id="criteria"> <if test="id != null">id = #{id}</if> <if test="companyName != null">and company_name = #{companyName}</if> <if test="status != null">and status =#{status}</if> <if test="website != null">and website =#{website}</if> <if test="isHaveImage != null">and is_have_image =#{isHaveImage}</if> <if test="type != null">and type =#{type}</if> <if test="image != null">and image =#{image}</if> <if test="createTime != null">and create_time >= #{createTime}</if> <if test="updateTime != null">and #{updateTime} >= update_time</if> </sql> <insert id="add" parameterType="cn.wisenergy.model.app.Banner" keyProperty="id" useGeneratedKeys="true"> insert into <include refid="table"/> (<include refid="cols_exclude_id"/>) value( <include refid="vals"/> ) </insert> <update id="edit" parameterType="cn.wisenergy.model.app.Banner"> UPDATE <include refid="table"/> <set> <include refid="updateCondition"/> </set> <where> id = #{id} </where> </update> <delete id="delById" parameterType="java.lang.Integer"> delete from <include refid="table"/> where id = #{id} </delete> <select id="getList" resultType="cn.wisenergy.model.dto.BannerDto" parameterType="map"> select <include refid="cols_all"/> from <include refid="table"/> <where> <if test="status != null">and status =#{status}</if> <if test="type != null">and type =#{type}</if> </where> order by create_time desc limit #{pageNo},#{pageSize} </select> <select id="count" resultType="java.lang.Integer"> select count(1) from <include refid="table"/> <where> <if test="status != null">and status =#{status}</if> <if test="type != null">and type =#{type}</if> </where> </select> <select id="getById" resultMap="advertisingMap"> select <include refid="cols_all"/> from <include refid="table"/> where id=#{id} </select> <select id="getTopBanners" resultType="cn.wisenergy.model.app.Banner"> select <include refid="cols_all"/> from <include refid="table"/> where status=1 and type=#{type} </select> <update id="editStatus"> UPDATE <include refid="table"/> <set> status=#{status} </set> <where> id = #{id} </where> </update> </mapper>