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.
banban/src/main/java/com/mapper/CommentMapper.xml

75 lines
5.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">
<!-- 该 XML 文件为 MyBatis 的映射文件,用于定义与数据库交互的 SQL 语句以及结果集映射关系等配置。此映射文件对应的接口为 com.mapper.CommentMapper -->
<mapper namespace="com.mapper.CommentMapper">
<!-- 定义一个名为 BaseResultMap 的结果集映射,用于将从数据库查询返回的结果(以列的形式)映射到 com.entity.Comment 实体类的对应属性上。
这样 MyBatis 在执行查询操作后,能自动将数据库记录转换为对应的 Java 对象方便后续使用。 -->
<resultMap type="com.entity.Comment" id="BaseResultMap">
<!-- 将数据库表中的 comment_id 列的值映射到 Comment 实体类的 comment_id 属性上,属性类型为 long -->
<id property="comment_id" column="comment_id" javaType="long"/>
<!-- 将数据库表中的 comment_content 列的值映射到 Comment 实体类的 comment_content 属性上,属性类型为 java.lang.String -->
<result property="comment_content" column="comment_content" javaType="java.lang.String"/>
<!-- 将数据库表中的 comment_time 列的值映射到 Comment 实体类的 comment_time 属性上,属性类型为 java.util.Date -->
<result property="comment_time" column="comment_time" javaType="java.util.Date"/>
<!-- 将数据库表中的 movie_id 列的值映射到 Comment 实体类的 movie_id 属性上,属性类型为 long -->
<result property="movie_id" column="movie_id" javaType="long"/>
<!-- 将数据库表中的 user_id 列的值映射到 Comment 实体类的 user_id 属性上,属性类型为 long -->
<result property="user_id" column="user_id" javaType="long"/>
</resultMap>
<!-- 定义一个名为 findCommentById 的查询语句用于根据评论的唯一标识ID从 comment 表中查询对应的评论信息。
参数类型为 long表示传入的参数是一个长整型的评论 ID查询结果通过 BaseResultMap 定义的映射关系转换为 Comment 实体对象返回。 -->
<select id="findCommentById" parameterType="long" resultMap="BaseResultMap">
select * from comment where comment_id = #{comment_id}
</select>
<!-- 定义一个名为 findAllComments 的查询语句,用于从 comment 表中查询所有的评论信息。
查询结果通过 BaseResultMap 定义的映射关系转换为 Comment 实体对象,并以列表形式返回所有的评论记录对应的 Comment 对象集合。 -->
<select id="findAllComments" resultMap="BaseResultMap">
select * from comment
</select>
<!-- 定义一个名为 findCommentsByUserName 的查询语句,用于根据用户名从 comment 表中查询该用户发表的所有评论信息。
参数类型为 java.lang.String表示传入的参数是一个字符串类型的用户名通过关联 comment 表和 user 表(根据 user_id 关联),筛选出指定用户名对应的评论记录,
结果同样通过 BaseResultMap 映射为 Comment 实体对象并返回对应的评论集合。 -->
<select id="findCommentsByUserName" parameterType="java.lang.String" resultMap="BaseResultMap">
select comment.* from comment,user where comment.user_id = user.user_id and user.user_name = #{user_name}
</select>
<!-- 定义一个名为 findCommentsByMoiveId 的查询语句用于根据电影的唯一标识ID从 comment 表中查询该电影对应的所有评论信息。
参数类型为 long表示传入的参数是一个长整型的电影 ID查询结果通过 BaseResultMap 映射为 Comment 实体对象并返回对应的评论集合。 -->
<select id="findCommentsByMoiveId" parameterType="long" resultMap="BaseResultMap">
select * from comment where movie_id = #{movie_id}
</select>
<!-- 定义一个名为 addComemnt 的插入语句,用于向 comment 表中插入一条新的评论记录。
参数类型为 com.entity.Comment表示传入的参数是一个 Comment 实体对象,从该对象中获取相应属性值插入到 comment 表对应的列中,插入的列包括 comment_content、comment_time、movie_id 和 user_id。 -->
<insert id="addComemnt" parameterType="com.entity.Comment">
insert into comment(comment_content,comment_time,movie_id,user_id)
values(#{comment_content},#{comment_time},#{movie_id},#{user_id})
</insert>
<!-- 定义一个名为 updateComment 的更新语句,用于更新 comment 表中指定评论记录的信息。
参数类型为 com.entity.Comment表示传入的参数是一个 Comment 实体对象,根据该对象中的属性值来更新对应评论记录的 comment_content、comment_time、movie_id 和 user_id 列的值,
更新条件是 comment_id 列的值与传入对象的 comment_id 属性值相等,通过 <set> 标签来动态生成需要更新的列,避免不必要的列更新为空值等情况。 -->
<update id="updateComment" parameterType="com.entity.Comment">
update comment
<set>
comment_content = #{comment_content},
comment_time = #{comment_time},
movie_id = #{movie_id},
user_id = #{user_id}
</set>
where comment_id = #{comment_id}
</update>
<!-- 定义一个名为 deleteComment 的删除语句,用于从 comment 表中删除指定评论记录。
参数类型为 long表示传入的参数是一个长整型的评论 ID根据该 ID 删除 comment 表中对应的评论记录,删除条件是 comment_id 列的值与传入的参数值相等。 -->
<delete id="deleteComment" parameterType="long">
delete from comment where comment_id = #{comment_id}
</delete>
</mapper>