<?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.ProductMapper"> <resultMap id="productMap" type="cn.wisenergy.model.app.ProductInfo"> <id column="id" property="id"/> <result column="batch_number" property="batchNumber"/> <result column="brand" property="brand"/> <result column="specification" property="specification"/> <result column="brand_name" property="brandName"/> <result column="product_country" property="productCountry"/> <result column="valid_time" property="validTime"/> <result column="company_name" property="companyName"/> <result column="company_address" property="companyAddress"/> <result column="company_url" property="companyUrl"/> <result column="tracking_number" property="trackingNumber"/> <result column="logistics_url" property="logisticsUrl"/> <result column="record_number" property="recordNumber"/> <result column="create_time" property="createTime"/> <result column="update_time" property="updateTime"/> </resultMap> <sql id="table"> product_info </sql> <sql id="cols_all"> id, <include refid="cols_exclude_id"/> </sql> <sql id="cols_exclude_id"> batch_number,brand,specification,brand_name,product_country, valid_time, company_name,company_address, company_url,tracking_number, logistics_url,record_number, create_time,update_time </sql> <sql id="vals"> #{batchNumber},#{brand}, #{specification},#{brandName},#{productCountry}, #{validTime},#{companyName}, #{companyAddress},#{companyUrl},#{trackingNumber},#{logisticsUrl}, #{recordNumber},now(),now() </sql> <sql id="createsVal"> #{i.batchNumber},#{i.brand},#{i.specification},#{i.brandName},#{i.productCountry}, #{i.validTime},#{i.companyName}, #{i.companyAddress}, #{i.companyUrl},#{i.trackingNumber},#{i.logisticsUrl}, #{i.recordNumber},now(),now() </sql> <sql id="updateCondition"> <if test="batchNumber != null">batch_number = #{batchNumber},</if> <if test="brand != null">brand = #{brand},</if> <if test="specification != null">specification = #{specification},</if> <if test="brandName != null">brand_name = #{brandName},</if> <if test="productCountry != null">product_country = #{productCountry},</if> <if test="validTime != null">valid_time = #{validTime},</if> <if test="companyName != null">company_name = #{companyName},</if> <if test="companyAddress != null">company_address = #{companyAddress},</if> <if test="companyUrl != null">company_url = #{companyUrl},</if> <if test="trackingNumber != null">tracking_number = #{trackingNumber},</if> <if test="logisticsUrl != null">logistics_url = #{logisticsUrl},</if> <if test="recordNumber != null">record_number = #{recordNumber},</if> update_time =now() </sql> <sql id="criteria"> <if test="id != null">id = #{id}</if> <if test="batchNumber != null">and batch_number = #{batchNumber}</if> <if test="brand != null">and brand = #{brand}</if> <if test="specification != null">and specification = #{specification}</if> <if test="brandName != null">and brand_name = #{brandName}</if> <if test="productCountry != null">and product_country = #{productCountry}</if> <if test="validTime != null">and valid_time = #{validTime}</if> <if test="companyName != null">and company_name = #{companyName}</if> <if test="companyAddress != null">and company_address = #{companyAddress}</if> <if test="companyUrl != null">and company_url = #{companyUrl}</if> <if test="trackingNumber != null">and tracking_number = #{trackingNumber}</if> <if test="logisticsUrl != null">and logistics_url = #{logisticsUrl}</if> <if test="recordNumber != null">and record_number = #{recordNumber}</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.ProductInfo" 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.ProductInfo"> UPDATE <include refid="table"/> <set> <include refid="updateCondition"/> </set> <where> id = #{id} </where> </update> <select id="getByBatchNumber" resultMap="productMap"> select <include refid="cols_all"/> from <include refid="table"/> <where> batch_number=#{batchNumber} </where> </select> </mapper>