pull/4/head
zhouyu 9 months ago
parent c8135e8683
commit e577c3ec8e

@ -1,9 +1,17 @@
<?xml version="1.0" encoding="UTF-8" ?>
<?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" >
<!-- 此为MyBatis的Mapper配置文件namespace属性指定了该Mapper对应的接口全限定名
MyBatis会依据这个namespace将这里定义的SQL语句与对应接口中的方法进行关联方便调用和映射。
这里对应的接口是com.njupt.swg.dao.ShippingMapper意味着这个文件中的SQL语句是为该接口中定义的方法提供具体实现的 -->
<mapper namespace="com.njupt.swg.dao.ShippingMapper" >
<!-- 定义了一个名为BaseResultMap的结果映射配置用于将从数据库查询返回的结果集映射到Java对象具体类型为com.njupt.swg.entity.Shipping上。
通过<constructor>元素来指定构造函数参数与数据库表列之间的映射关系详细说明了每个列对应的Java类型和JDBC类型等信息
这样MyBatis就能准确地将查询结果中的数据填充到对应的Java对象中 -->
<resultMap id="BaseResultMap" type="com.njupt.swg.entity.Shipping" >
<constructor >
<idArg column="id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<!-- 以下每个<arg>元素都对应着Shipping实体类构造函数的一个参数指定了数据库表列名、对应的JDBC类型以及Java类型
按照顺序依次为user_id、receiver_name等列用于将查询结果准确地映射到Shipping对象的对应属性上 -->
<arg column="user_id" jdbcType="INTEGER" javaType="java.lang.Integer" />
<arg column="receiver_name" jdbcType="VARCHAR" javaType="java.lang.String" />
<arg column="receiver_phone" jdbcType="VARCHAR" javaType="java.lang.String" />
@ -17,171 +25,201 @@
<arg column="update_time" jdbcType="TIMESTAMP" javaType="java.util.Date" />
</constructor>
</resultMap>
<!-- 定义了一个名为Base_Column_List的SQL片段包含了一系列数据库表中的列名这些列名通常是在查询、插入、更新等操作中经常需要用到的。
通过定义这个片段可以在其他SQL语句中方便地复用这些列名提高代码的可维护性和简洁性 -->
<sql id="Base_Column_List" >
id, user_id, receiver_name, receiver_phone, receiver_mobile, receiver_province, receiver_city,
receiver_district, receiver_address, receiver_zip, create_time, update_time
id, user_id, receiver_name, receiver_phone, receiver_mobile, receiver_province, receiver_city,
receiver_district, receiver_address, receiver_zip, create_time, update_time
</sql>
<!-- 定义了一个名为selectByPrimaryKey的查询语句用于根据主键id从数据库表mmall_shipping中查询记录。
resultMap属性指定了使用前面定义的BaseResultMap来将查询结果映射到对应的Java对象Shipping类型
parameterType指定了传入参数的类型为java.lang.Integer也就是主键的类型意味着这个查询语句期望接收一个整数类型的主键值作为参数。
SQL语句内部通过<include>标签引用了Base_Column_List片段来指定要查询的具体列然后在where子句中通过#{id,jdbcType=INTEGER}的方式,
根据传入的主键值进行筛选,以获取对应主键的记录 -->
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
select
<include refid="Base_Column_List" />
from mmall_shipping
where id = #{id,jdbcType=INTEGER}
</select>
<!-- 定义了一个名为deleteByPrimaryKey的删除语句用于根据主键id从数据库表mmall_shipping中删除对应的记录。
parameterType指定了传入参数的类型为java.lang.Integer即主键的类型表明该删除语句期望接收一个整数类型的主键值作为参数
SQL语句中通过where子句使用#{id,jdbcType=INTEGER}的方式,根据传入的主键值确定要删除的具体记录 -->
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
delete from mmall_shipping
where id = #{id,jdbcType=INTEGER}
</delete>
<!-- 定义了一个名为insert的插入语句用于向mmall_shipping表中插入一条新记录parameterType指定了传入参数的类型为com.njupt.swg.entity.Shipping
意味着这个插入语句期望接收一个Shipping类型的对象作为参数该对象包含了要插入的各列数据。
useGeneratedKeys="true"表示启用数据库自增长主键功能keyProperty="id"指定了将数据库生成的主键值赋给插入对象的id属性方便后续获取新插入记录的主键值。
SQL语句中明确列出了要插入的各列名以及对应的参数值通过#{列名,jdbcType=类型}的方式指定参数,如#{id,jdbcType=INTEGER}
对于create_time和update_time列使用了数据库函数now()来插入当前时间 -->
<insert id="insert" parameterType="com.njupt.swg.entity.Shipping" useGeneratedKeys="true" keyProperty="id">
insert into mmall_shipping (id, user_id, receiver_name,
receiver_phone, receiver_mobile, receiver_province,
receiver_city, receiver_district, receiver_address,
receiver_zip, create_time, update_time
)
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{receiverName,jdbcType=VARCHAR},
#{receiverPhone,jdbcType=VARCHAR}, #{receiverMobile,jdbcType=VARCHAR}, #{receiverProvince,jdbcType=VARCHAR},
#{receiverCity,jdbcType=VARCHAR}, #{receiverDistrict,jdbcType=VARCHAR}, #{receiverAddress,jdbcType=VARCHAR},
#{receiverZip,jdbcType=VARCHAR}, now(), now()
)
insert into mmall_shipping (id, user_id, receiver_name,
receiver_phone, receiver_mobile, receiver_province,
receiver_city, receiver_district, receiver_address,
receiver_zip, create_time, update_time
)
values (#{id,jdbcType=INTEGER}, #{userId,jdbcType=INTEGER}, #{receiverName,jdbcType=VARCHAR},
#{receiverPhone,jdbcType=VARCHAR}, #{receiverMobile,jdbcType=VARCHAR}, #{receiverProvince,jdbcType=VARCHAR},
#{receiverCity,jdbcType=VARCHAR}, #{receiverDistrict,jdbcType=VARCHAR}, #{receiverAddress,jdbcType=VARCHAR},
#{receiverZip,jdbcType=VARCHAR}, now(), now()
)
</insert>
<!-- 定义了一个名为insertSelective的插入语句相较于前面的insert语句它更具选择性只会插入那些非空值的列。
通过<trim>标签结合<if>标签来实现动态SQL拼接<trim>标签用于去除多余的逗号等字符,<if>标签根据传入的Shipping对象的属性是否为null来决定是否添加对应的列和值到SQL语句中。
例如如果Shipping对象的id属性不为null就会在SQL语句的列部分添加id列在值部分添加对应的#{id,jdbcType=INTEGER}参数,以此类推,对其他列也进行类似的条件判断插入操作,
这样可以更灵活地根据实际传入的对象数据情况进行插入操作避免插入不必要的null值 -->
<insert id="insertSelective" parameterType="com.njupt.swg.entity.Shipping" >
insert into mmall_shipping
<trim prefix="(" suffix=")" suffixOverrides="," >
<if test="id != null" >
<if test="id!= null" >
id,
</if>
<if test="userId != null" >
<if test="userId!= null" >
user_id,
</if>
<if test="receiverName != null" >
<if test="receiverName!= null" >
receiver_name,
</if>
<if test="receiverPhone != null" >
<if test="receiverPhone!= null" >
receiver_phone,
</if>
<if test="receiverMobile != null" >
<if test="receiverMobile!= null" >
receiver_mobile,
</if>
<if test="receiverProvince != null" >
<if test="receiverProvince!= null" >
receiver_province,
</if>
<if test="receiverCity != null" >
<if test="receiverCity!= null" >
receiver_city,
</if>
<if test="receiverDistrict != null" >
<if test="receiverDistrict!= null" >
receiver_district,
</if>
<if test="receiverAddress != null" >
<if test="receiverAddress!= null" >
receiver_address,
</if>
<if test="receiverZip != null" >
<if test="receiverZip!= null" >
receiver_zip,
</if>
<if test="createTime != null" >
<if test="createTime!= null" >
create_time,
</if>
<if test="updateTime != null" >
<if test="updateTime!= null" >
update_time,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides="," >
<if test="id != null" >
<if test="id!= null" >
#{id,jdbcType=INTEGER},
</if>
<if test="userId != null" >
<if test="userId!= null" >
#{userId,jdbcType=INTEGER},
</if>
<if test="receiverName != null" >
<if test="receiverName!= null" >
#{receiverName,jdbcType=VARCHAR},
</if>
<if test="receiverPhone != null" >
<if test="receiverPhone!= null" >
#{receiverPhone,jdbcType=VARCHAR},
</if>
<if test="receiverMobile != null" >
<if test="receiverMobile!= null" >
#{receiverMobile,jdbcType=VARCHAR},
</if>
<if test="receiverProvince != null" >
<if test="receiverProvince!= null" >
#{receiverProvince,jdbcType=VARCHAR},
</if>
<if test="receiverCity != null" >
<if test="receiverCity!= null" >
#{receiverCity,jdbcType=VARCHAR},
</if>
<if test="receiverDistrict != null" >
<if test="receiverDistrict!= null" >
#{receiverDistrict,jdbcType=VARCHAR},
</if>
<if test="receiverAddress != null" >
<if test="receiverAddress!= null" >
#{receiverAddress,jdbcType=VARCHAR},
</if>
<if test="receiverZip != null" >
<if test="receiverZip!= null" >
#{receiverZip,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
<if test="createTime!= null" >
now(),
</if>
<if test="updateTime != null" >
<if test="updateTime!= null" >
now(),
</if>
</trim>
</insert>
<!-- 定义了一个名为updateByPrimaryKeySelective的更新语句用于根据主键id有选择性地更新mmall_shipping表中的记录。
通过<set>标签结合<if>标签实现动态SQL拼接<if>标签根据传入的Shipping对象的各属性是否为null来决定是否添加对应的更新语句到SQL中。
例如如果Shipping对象的userId属性不为null就会在<set>标签内添加user_id = #{userId,jdbcType=INTEGER}这样的更新语句,以此类推,对其他属性也进行类似判断更新操作,
最后通过where子句根据主键值#{id,jdbcType=INTEGER})确定要更新的具体记录,这样可以只更新那些有实际值变化的列,避免不必要的全列更新 -->
<update id="updateByPrimaryKeySelective" parameterType="com.njupt.swg.entity.Shipping" >
update mmall_shipping
<set >
<if test="userId != null" >
<if test="userId!= null" >
user_id = #{userId,jdbcType=INTEGER},
</if>
<if test="receiverName != null" >
<if test="receiverName!= null" >
receiver_name = #{receiverName,jdbcType=VARCHAR},
</if>
<if test="receiverPhone != null" >
<if test="receiverPhone!= null" >
receiver_phone = #{receiverPhone,jdbcType=VARCHAR},
</if>
<if test="receiverMobile != null" >
<if test="receiverMobile!= null" >
receiver_mobile = #{receiverMobile,jdbcType=VARCHAR},
</if>
<if test="receiverProvince != null" >
<if test="receiverProvince!= null" >
receiver_province = #{receiverProvince,jdbcType=VARCHAR},
</if>
<if test="receiverCity != null" >
<if test="receiverCity!= null" >
receiver_city = #{receiverCity,jdbcType=VARCHAR},
</if>
<if test="receiverDistrict != null" >
<if test="receiverDistrict!= null" >
receiver_district = #{receiverDistrict,jdbcType=VARCHAR},
</if>
<if test="receiverAddress != null" >
<if test="receiverAddress!= null" >
receiver_address = #{receiverAddress,jdbcType=VARCHAR},
</if>
<if test="receiverZip != null" >
<if test="receiverZip!= null" >
receiver_zip = #{receiverZip,jdbcType=VARCHAR},
</if>
<if test="createTime != null" >
<if test="createTime!= null" >
create_time = #{createTime,jdbcType=TIMESTAMP},
</if>
<if test="updateTime != null" >
<if test="updateTime!= null" >
update_time = now(),
</if>
</set>
where id = #{id,jdbcType=INTEGER}
</update>
<!-- 定义了一个名为updateByPrimaryKey的更新语句用于根据主键id更新mmall_shipping表中的记录。
该语句会对Shipping对象对应的所有列进行更新不管传入的对象各属性是否为null都会将对应列的值更新到数据库表中
通过where子句根据主键值#{id,jdbcType=INTEGER})确定要更新的具体记录 -->
<update id="updateByPrimaryKey" parameterType="com.njupt.swg.entity.Shipping" >
update mmall_shipping
set user_id = #{userId,jdbcType=INTEGER},
receiver_name = #{receiverName,jdbcType=VARCHAR},
receiver_phone = #{receiverPhone,jdbcType=VARCHAR},
receiver_mobile = #{receiverMobile,jdbcType=VARCHAR},
receiver_province = #{receiverProvince,jdbcType=VARCHAR},
receiver_city = #{receiverCity,jdbcType=VARCHAR},
receiver_district = #{receiverDistrict,jdbcType=VARCHAR},
receiver_address = #{receiverAddress,jdbcType=VARCHAR},
receiver_zip = #{receiverZip,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = now()
receiver_name = #{receiverName,jdbcType=VARCHAR},
receiver_phone = #{receiverPhone,jdbcType=VARCHAR},
receiver_mobile = #{receiverMobile,jdbcType=VARCHAR},
receiver_province = #{receiverProvince,jdbcType=VARCHAR},
receiver_city = #{receiverCity,jdbcType=VARCHAR},
receiver_district = #{receiverDistrict,jdbcType=VARCHAR},
receiver_address = #{receiverAddress,jdbcType=VARCHAR},
receiver_zip = #{receiverZip,jdbcType=VARCHAR},
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = now()
where id = #{id,jdbcType=INTEGER}
</update>
<!-- 定义了一个名为deleteByUserIdShippingId的删除语句用于根据用户IDuserId和地址IDshippingId从mmall_shipping表中删除对应的记录。
parameterType指定了传入参数的类型为map意味着这个删除语句期望接收一个包含userId和shippingId键值对的Map对象作为参数
SQL语句中通过WHERE子句使用#{userId}和#{shippingId}的方式根据传入的Map中的对应值确定要删除的具体记录 -->
<delete id="deleteByUserIdShippingId" parameterType="map">
DELETE from mmall_shipping WHERE user_id=#{userId} and id = #{shippingId}
</delete>
<update id="updateByShipping" parameterType="com.njupt.swg.entity.Shipping">
<!-- 定义了一个名为updateByShipping的更新语句用于根据Shipping对象的相关属性以及主键id和用户IDuserId来更新mmall_shipping表中的记录。
该语句会对Shipping对象对应的多个列进行更新不管传入的对象各属性是否为null都会将对应列的值更新到数据库表中
通过where子句根据主键值#{id,jdbcType=INTEGER}和用户ID值#{userId,jdbcType=INTEGER})确定要更新的具体记录 -->
<update id="updateByShipping" parameterType="com.njupt.swg.entity.Shipping">
update mmall_shipping
set
receiver_name = #{receiverName,jdbcType=VARCHAR},
@ -195,14 +233,12 @@
create_time = #{createTime,jdbcType=TIMESTAMP},
update_time = now()
where id = #{id,jdbcType=INTEGER}
and user_id = #{userId,jdbcType=INTEGER}
and user_id = #{userId,jdbcType=INTEGER}
</update>
<!-- 定义了一个名为selectByUserIdShippingId的查询语句用于根据用户IDuserId和地址IDshippingId从mmall_shipping表中查询对应的记录。
parameterType指定了传入参数的类型为map意味着这个查询语句期望接收一个包含userId和shippingId键值对的Map对象作为参数
resultMap属性指定了使用前面定义的BaseResultMap来将查询结果映射到对应的Java对象Shipping类型
SQL语句中通过<include>标签引用了Base_Column_List片段来指定要查询的具体列然后在where子句中通过#{userId}和#{shippingId}的方式,
根据传入的Map中的对应值进行筛选以获取符合条件的记录 -->
<select id="selectByUserIdShippingId" parameterType="map" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/> from mmall_shipping where user_id = #{userId} and id = #{shippingId}
</select>
<select id="selectByUserId" parameterType="int" resultMap="BaseResultMap">
SELECT <include refid="Base_Column_List"/> from mmall_shipping where user_id = #{userId}
</select>
</mapper>
SELECT <include refid="Base_Column_List"/>
Loading…
Cancel
Save