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.

81 lines
2.8 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">
<!-- 公告表数据映射文件 -->
<mapper namespace="com.example.mapper.NoticeMapper">
<!-- 定义公告表基础字段列表 -->
<sql id="Base_Column_List">
id,title,content,time,user
</sql>
<!-- 查询所有公告(支持条件查询) -->
<select id="selectAll" resultType="com.example.entity.Notice">
select
<include refid="Base_Column_List" />
from notice
<where>
<if test="id != null"> and id= #{id}</if>
<if test="title != null"> and title like concat('%', #{title}, '%')</if> <!-- 标题模糊搜索 -->
<if test="content != null"> and content= #{content}</if>
<if test="time != null"> and time= #{time}</if>
<if test="user != null"> and user= #{user}</if>
</where>
order by id desc <!-- 按ID降序排列新的公告在前 -->
</select>
<!-- 根据ID查询单个公告 -->
<select id="selectById" resultType="com.example.entity.Notice">
select
<include refid="Base_Column_List" />
from notice
where id = #{id}
</select>
<!-- 根据ID删除公告 -->
<delete id="deleteById">
delete from notice
where id = #{id}
</delete>
<!-- 新增公告 -->
<insert id="insert" parameterType="com.example.entity.Notice" useGeneratedKeys="true">
insert into notice
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="id != null">id,</if>
<if test="title != null">title,</if>
<if test="content != null">content,</if>
<if test="time != null">time,</if>
<if test="user != null">user,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="id != null">#{id},</if>
<if test="title != null">#{title},</if>
<if test="content != null">#{content},</if>
<if test="time != null">#{time},</if>
<if test="user != null">#{user},</if>
</trim>
</insert>
<!-- 根据ID修改公告信息 -->
<update id="updateById" parameterType="com.example.entity.Notice">
update notice
<set>
<if test="title != null">
title = #{title}, <!-- 公告标题 -->
</if>
<if test="content != null">
content = #{content}, <!-- 公告内容 -->
</if>
<if test="time != null">
time = #{time}, <!-- 发布时间 -->
</if>
<if test="user != null">
user = #{user}, <!-- 发布人 -->
</if>
</set>
where id = #{id}
</update>
</mapper>