You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ForestBlog/src/resources/mapper/LinkMapper.xml

96 lines
5.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?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">
<!-- 定义了一个名为com.liuyanzhao.ssm.blog.mapper.LinkMapper的命名空间用于组织SQL语句 -->
<mapper namespace="com.liuyanzhao.ssm.blog.mapper.LinkMapper">
<!-- 定义了一个resultMap用于映射数据库列和Java对象属性 -->
<resultMap id="BaseResultMap" type="com.liuyanzhao.ssm.blog.entity.Link">
<id column="link_id" property="linkId" jdbcType="INTEGER"/> <!-- 链接ID -->
<result column="link_url" property="linkUrl" jdbcType="VARCHAR"/> <!-- 链接URL -->
<result column="link_name" property="linkName" jdbcType="VARCHAR"/> <!-- 链接名称 -->
<result column="link_image" property="linkImage" jdbcType="VARCHAR"/> <!-- 链接图片 -->
<result column="link_description" property="linkDescription" jdbcType="VARCHAR"/> <!-- 链接描述 -->
<result column="link_owner_nickname" property="linkOwnerNickname" jdbcType="VARCHAR"/> <!-- 链接所有者昵称 -->
<result column="link_owner_contact" property="linkOwnerContact" jdbcType="VARCHAR"/> <!-- 链接所有者联系方式 -->
<result column="link_update_time" property="linkUpdateTime" jdbcType="TIMESTAMP"/> <!-- 链接更新时间 -->
<result column="link_create_time" property="linkCreateTime" jdbcType="TIMESTAMP"/> <!-- 链接创建时间 -->
<result column="link_order" property="linkOrder" jdbcType="INTEGER"/> <!-- 链接排序 -->
<result column="link_status" property="linkStatus" jdbcType="INTEGER"/> <!-- 链接状态 -->
</resultMap>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用列名 -->
<sql id="Base_Column_List">
link_id, link_url, link_name, link_image, link_description, link_owner_nickname,
link_owner_contact, link_update_time, link_create_time, link_order, link_status
</sql>
<!-- 定义了一个SQL片段用于在其他SQL语句中引用表名 -->
<sql id="tb">link</sql>
<!-- 根据ID获取链接 -->
<select id="getLinkById" resultMap="BaseResultMap" parameterType="java.lang.Integer">
select
<include refid="Base_Column_List" />
from link
where link_id = #{linkId,jdbcType=INTEGER}
</select>
<!-- 根据ID删除链接 -->
<delete id="deleteById" parameterType="java.lang.Integer">
delete from link
where link_id = #{linkId,jdbcType=INTEGER}
</delete>
<!-- 插入一个新的链接 -->
<insert id="insert" parameterType="com.liuyanzhao.ssm.blog.entity.Link" useGeneratedKeys="true" keyProperty="linkId">
insert into link (link_id, link_url, link_name,
link_image, link_description, link_owner_nickname,
link_owner_contact, link_update_time, link_create_time,
link_order, link_status)
values (#{linkId,jdbcType=INTEGER}, #{linkUrl,jdbcType=VARCHAR}, #{linkName,jdbcType=VARCHAR},
#{linkImage,jdbcType=VARCHAR}, #{linkDescription,jdbcType=VARCHAR}, #{linkOwnerNickname,jdbcType=VARCHAR},
#{linkOwnerContact,jdbcType=VARCHAR}, #{linkUpdateTime,jdbcType=TIMESTAMP}, #{linkCreateTime,jdbcType=TIMESTAMP},
#{linkOrder,jdbcType=INTEGER}, #{linkStatus,jdbcType=INTEGER})
</insert>
<!-- 更新链接信息 -->
<update id="update" parameterType="com.liuyanzhao.ssm.blog.entity.Link">
update link
<set>
<if test="linkUrl != null" > link_url = #{linkUrl,jdbcType=VARCHAR},</if>
<if test="linkName != null" >link_name = #{linkName,jdbcType=VARCHAR},</if>
<if test="linkImage != null" >link_image = #{linkImage,jdbcType=VARCHAR},</if>
<if test="linkDescription != null" >link_description = #{linkDescription,jdbcType=VARCHAR},</if>
<if test="linkOwnerNickname != null" >link_owner_nickname = #{linkOwnerNickname,jdbcType=VARCHAR},</if>
<if test="linkOwnerContact != null" >link_owner_contact = #{linkOwnerContact,jdbcType=VARCHAR},</if>
<if test="linkUpdateTime != null" >link_update_time = #{linkUpdateTime,jdbcType=TIMESTAMP},</if>
<if test="linkCreateTime != null" >link_create_time = #{linkCreateTime,jdbcType=TIMESTAMP},</if>
<if test="linkOrder != null" >link_order = #{linkOrder,jdbcType=INTEGER}, </if>
<if test="linkStatus != null" >link_status = #{linkStatus,jdbcType=INTEGER},</if>
</set>
where link_id = #{linkId,jdbcType=INTEGER}
</update>
<!-- 获取链接总数 -->
<select id="countLink" resultType="Integer">
SELECT COUNT(*) FROM <include refid="tb"/>
<where>
<if test="status!=null">
link_status=#{status}
</if>
</where>
</select>
<!-- 获取链接列表 -->
<select id="listLink" resultType="com.liuyanzhao.ssm.blog.entity.Link">
SELECT
<include refid="Base_Column_List"/>
FROM <include refid="tb"/>
<where>
<if test="status!=null">
link_status=#{status}
</if>
</where>
ORDER BY link_status ASC,link_order DESC,link_id ASC
</select>
</mapper>