发表于: 2025-07-06 20:15:11
0 10
今天完成的事情:(一定要写非常细致的内容,比如说学会了盒子模型,了解了Margin)
<?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.WorkMapper">
<select id="selectByIds" resultType="org.example.model.Work">
SELECT * FROM works WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</select>
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
INSERT INTO works
(pid, level, name, state, create_at, update_at, author, sort
<if test="level == 2">, introduce, image, url, picture, article</if>)
VALUES
(#{pid}, #{level}, #{name}, #{state}, #{createAt}, #{updateAt}, #{author}, #{sort}
<if test="level == 2">, #{introduce}, #{image}, #{url}, #{picture}, #{article}</if>)
</insert>
<update id="batchUpdateSort">
UPDATE works
SET sort = CASE id
<foreach collection="works" item="work">
WHEN #{work.id} THEN #{work.sort}
</foreach>
END
WHERE id IN
<foreach collection="works" item="work" open="(" separator="," close=")">
#{work.id}
</foreach>
</update>
<update id="update" parameterType="Work">
UPDATE works SET
pid = #{pid},
level = #{level},
name = #{name},
state = #{state},
update_at = #{updateAt},
author = #{author},
sort = #{sort}
<if test="level == 2">,
introduce = #{introduce},
image = #{image},
url = #{url},
picture = #{picture}
article = #{article}
</if>
WHERE id = #{id}
</update>
<select id="selectByCondition" resultType="Work" parameterType="java.lang.String">
SELECT * FROM works
WHERE 1=1
<if test="name != null">
AND name = #{name}
</if>
<if test="state != null">
AND state = #{state}
</if>
<if test="pid != null">
AND pid = #{pid}
</if>
</select>
<select id="selectById" resultType="Work">
SELECT * FROM works WHERE id = #{id}
</select>
<select id="selectByLevel" resultType="Work">
SELECT
id, pid, level, name, state,
create_at, update_at, author, sort,
<if test="level == 2">
introduce, image, url, picture, article
</if>
<if test="level != 2">
null as introduce, null as image, null as url, null as picture, null as article
</if>
FROM works
WHERE level = #{level}
ORDER BY sort
</select>
<delete id="deleteById">
DELETE FROM works WHERE id = #{id}
</delete>
</mapper>
明天计划的事情:(一定要写非常细致的内容)
遇到的问题:(遇到什么困难,怎么解决的)
收获:(通过今天的学习,学到了什么知识)
评论