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.

79 lines
3.3 KiB

<?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="org.example.mapper.NoticeMapper">
<resultMap type="Notice" id="NoticeResult">
<result property="id" column="id" />
<result property="userId" column="userId" />
<result property="name" column="name" />
<result property="title" column="title" />
<result property="content" column="content" />
<result property="remark" column="remark" />
<association property="user" column="userId" select="org.example.mapper.UserMapper.selectUserById"></association>
</resultMap>
<sql id="selectNoticeVo">
select id, userId, name, title, content, remark from notice
</sql>
<select id="selectNoticeList" parameterType="Notice" resultMap="NoticeResult">
<include refid="selectNoticeVo"/>
<where>
<if test="userId != null "> and userId = #{userId}</if>
<if test="name != null and name != ''"> and name like concat('%', #{name}, '%')</if>
<if test="title != null and title != ''"> and title like concat('%', #{title}, '%')</if>
<if test="content != null and content != ''"> and content like concat('%', #{content}, '%')</if>
</where>
order by id desc
</select>
<select id="selectNoticeById" parameterType="Long" resultMap="NoticeResult">
<include refid="selectNoticeVo"/>
where id = #{id}
order by id desc
</select>
<insert id="insertNotice" parameterType="Notice" useGeneratedKeys="true" keyProperty="id">
insert into notice
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="userId != null">userId,</if>
<if test="name != null and name != ''">name,</if>
<if test="title != null and title != ''">title,</if>
<if test="content != null and content != ''">content,</if>
<if test="remark != null">remark,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="userId != null">#{userId},</if>
<if test="name != null and name != ''">#{name},</if>
<if test="title != null and title != ''">#{title},</if>
<if test="content != null and content != ''">#{content},</if>
<if test="remark != null">#{remark},</if>
</trim>
</insert>
<update id="updateNotice" parameterType="Notice">
update notice
<trim prefix="SET" suffixOverrides=",">
<if test="userId != null">userId = #{userId},</if>
<if test="name != null and name != ''">name = #{name},</if>
<if test="title != null and title != ''">title = #{title},</if>
<if test="content != null and content != ''">content = #{content},</if>
<if test="remark != null">remark = #{remark},</if>
</trim>
where id = #{id}
</update>
<delete id="deleteNoticeById" parameterType="Long">
delete from notice where id = #{id}
</delete>
<delete id="deleteNoticeByIds" parameterType="String">
delete from notice where id in
<foreach item="id" collection="array" open="(" separator="," close=")">
#{id}
</foreach>
</delete>
</mapper>