显示评论
数据层
记得先写实体类
- 根据实体查询一页评论数据
// 查询全部的评论并对其实现分页
List<Comment> selectCommentsByEntity(int entityType, int entityId, int offset, int limit);
- 根据实体查询评论的数量
// 查询数据的条目数
int selectCountByEntity(int entityType, int entityId);
<!-- SQL查询语句 -->
<sql id="selectFields">
id, user_id, entity_type, entity_id, target_id, content, status, create_time
</sql>
<!-- 查询数据并分页 -->
<select id="selectCommentsByEntity" resultType="Comment">
select <include refid="selectFields"></include>
from comment
where status = 0
and entity_type = #{entityType}
and entity_id = #{entityId}
order by create_time asc
limit #{offset}, #{limit}
</select>
<!-- 查询数据的条目数 -->
<select id="selectCountByEntity" resultType="int">
select count(id)
from comment
where status = 0
and entity_type = #{entityType}
and entity_id = #{entityId}
</select>
业务层
- 处理查询评论的业务
@Autowired(required = false)
private CommentMapper commentMapper;
// 实现 查询全部的评论并对其实现分页 的业务
public List<Comment> findCommentsByEntity(int entityType, int entityId, int offset, int limit) {
return commentMapper.selectCommentsByEntity