forum-backend/target/classes/mapper/BmsPostMapper.xml
2023-06-14 20:12:48 +08:00

79 lines
2.7 KiB
XML

<?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.yovinchen.forum.mapper.BmsTopicMapper">
<resultMap id="topicVO" type="com.yovinchen.forum.model.vo.PostVO">
<id column="id" property="id"/>
<result column="title" property="title"/>
<result column="user_id" property="userId"/>
<result column="comments" property="comments"/>
<result column="view" property="view"/>
<result column="collects" property="collects"/>
<result column="top" property="top"/>
<result column="essence" property="essence"/>
<result column="create_time" property="createTime"/>
<result column="modify_time" property="modifyTime"/>
<result column="username" property="username"/>
<result column="alias" property="alias"/>
<result column="avatar" property="avatar"/>
</resultMap>
<select id="selectListAndPage" resultMap="topicVO">
SELECT
t.id,t.title,t.user_id,t.comments,
t.view,t.collects,t.top,t.essence,
t.create_time ,t.modify_time ,
u.username,u.alias, u.avatar
FROM bms_post t
LEFT JOIN ums_user u
ON t.user_id = u.id
<!-- <where>-->
<!-- <if test="tab == 'hot'">-->
<!-- date(t.create_time) &lt;= date_add(curdate(), interval 1 day)-->
<!-- and date(t.create_time) &gt;= date_sub(curdate(), interval 7 day)-->
<!-- </if>-->
<!-- </where>-->
<if test="tab != 'hot'">
order by t.create_time desc
</if>
<if test="tab == 'hot'">
order by t.view desc, t.create_time desc
</if>
</select>
<select id="selectRecommend" resultType="com.yovinchen.forum.model.entity.BmsPost">
select *
from bms_post t
where t.id != #{id}
order by rand(), t.view
limit 10
</select>
<select id="searchByKey" resultMap="topicVO">
SELECT t.id,
t.title,
t.user_id,
t.comments,
t.view,
t.collects,
t.top,
t.essence,
t.create_time,
t.modify_time,
u.username,
u.alias,
u.avatar
FROM bms_post t
LEFT JOIN ums_user u
ON t.user_id = u.id
<where>
<if test="keyword!=null">
and t.title like CONCAT('%','${keyword}')
or t.title like CONCAT('${keyword}','%')
or t.title like CONCAT('%','${keyword}','%')
or t.title = #{keyword}
</if>
</where>
order by t.view desc, t.create_time desc
</select>
</mapper>