|
|
|
|
<?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">
|
|
|
|
|
<!-- 配置关于用户评论表的 MyBatis映射文件 -->
|
|
|
|
|
<!-- namespace:必须与对应的接口全类名一致 id:必须与对应接口的某个对应的方法名一致 -->
|
|
|
|
|
<mapper namespace="com.dao.TopicDAO">
|
|
|
|
|
<resultMap type="topic" id="topicMap">
|
|
|
|
|
<id property="topicid" column="topicid" />
|
|
|
|
|
<result property="usersid" column="usersid" />
|
|
|
|
|
<result property="articleid" column="articleid" />
|
|
|
|
|
<result property="contents" column="contents" />
|
|
|
|
|
<result property="addtime" column="addtime" />
|
|
|
|
|
<result property="username" column="username" />
|
|
|
|
|
<result property="title" column="title" />
|
|
|
|
|
<!-- 通过外键关联查询 返回封装Users对象 -->
|
|
|
|
|
<association property="users" column="usersid" select="com.dao.UsersDAO.getUsersById" javaType="com.entity.Users" />
|
|
|
|
|
<!-- 通过外键关联查询 返回封装Article对象 -->
|
|
|
|
|
<association property="article" column="articleid" select="com.dao.ArticleDAO.getArticleById" javaType="com.entity.Article" />
|
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
<!-- 用户评论表 插入SQL语句 TopicDAO通过ID(insertTopic)调用此配置 -->
|
|
|
|
|
<insert id="insertTopic" parameterType="topic">
|
|
|
|
|
insert into topic(topicid , usersid , articleid , contents , addtime ) values(#{topicid} , #{usersid} , #{articleid} , #{contents} , #{addtime} )
|
|
|
|
|
</insert>
|
|
|
|
|
|
|
|
|
|
<!-- 用户评论表 更新SQL语句 TopicDAO通过ID(updateTopic)调用此配置 -->
|
|
|
|
|
<update id="updateTopic" parameterType="topic">
|
|
|
|
|
update topic set usersid=#{usersid} , articleid=#{articleid} , contents=#{contents} , addtime=#{addtime} where topicid=#{topicid}
|
|
|
|
|
</update>
|
|
|
|
|
|
|
|
|
|
<!-- 用户评论表 按主键删除SQL语句 TopicDAO通过ID(deleteTopic)调用此配置 -->
|
|
|
|
|
<delete id="deleteTopic" parameterType="String">
|
|
|
|
|
delete from topic where topicid = #{topicid}
|
|
|
|
|
</delete>
|
|
|
|
|
|
|
|
|
|
<!-- 用户评论表 查询全部用户评论信息SQL语句 TopicDAO通过ID(getAllTopic)调用此配置 -->
|
|
|
|
|
<select id="getAllTopic" resultMap="topicMap">
|
|
|
|
|
select a.* , b.username , c.title from topic a , users b , article c where 1=1 and a.usersid = b.usersid and a.articleid = c.articleid order by topicid desc
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 用户评论表 按主键(topicid)查询SQL语句 TopicDAO通过ID(getTopicById)调用此配置 -->
|
|
|
|
|
<select id="getTopicById" parameterType="String" resultMap="topicMap">
|
|
|
|
|
select a.* , b.username , c.title from topic a , users b , article c where 1=1 and a.usersid = b.usersid and a.articleid = c.articleid and topicid=#{topicid} order by topicid desc
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 用户评论表 按条件精确查询SQL语句 TopicDAO通过ID(getTopicByCond)调用此配置 -->
|
|
|
|
|
<select id="getTopicByCond" parameterType="topic" resultMap="topicMap">
|
|
|
|
|
select a.* , b.username , c.title from topic a , users b , article c where 1=1 and a.usersid = b.usersid and a.articleid = c.articleid
|
|
|
|
|
<if test="usersid != null and '' != usersid">
|
|
|
|
|
and a.usersid = #{usersid}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="articleid != null and '' != articleid">
|
|
|
|
|
and a.articleid = #{articleid}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="contents != null and '' != contents">
|
|
|
|
|
and a.contents = #{contents}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="addtime != null and '' != addtime">
|
|
|
|
|
and a.addtime = #{addtime}
|
|
|
|
|
</if>
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!-- 用户评论表 按条件模糊查询SQL语句 TopicDAO通过ID(getTopicByLike)调用此配置 -->
|
|
|
|
|
<select id="getTopicByLike" parameterType="topic" resultMap="topicMap">
|
|
|
|
|
select a.* , b.username , c.title from topic a , users b , article c where 1=1 and a.usersid = b.usersid and a.articleid = c.articleid
|
|
|
|
|
<if test="usersid != null and '' != usersid">
|
|
|
|
|
and b.username like CONCAT('%', CONCAT(#{usersid}, '%'))
|
|
|
|
|
</if>
|
|
|
|
|
<if test="articleid != null and '' != articleid">
|
|
|
|
|
and c.title like CONCAT('%', CONCAT(#{articleid}, '%'))
|
|
|
|
|
</if>
|
|
|
|
|
<if test="contents != null and '' != contents">
|
|
|
|
|
and a.contents like CONCAT('%', CONCAT(#{contents}, '%'))
|
|
|
|
|
</if>
|
|
|
|
|
<if test="addtime != null and '' != addtime">
|
|
|
|
|
and a.addtime like CONCAT('%', CONCAT(#{addtime}, '%'))
|
|
|
|
|
</if>
|
|
|
|
|
</select>
|
|
|
|
|
</mapper>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|