springboot开发论坛学习 ---- 3.5+3.6

这篇博客详细介绍了如何使用SpringBoot开发论坛的评论功能,包括显示评论和添加评论两个部分。在数据层,涉及实体类和数据查询;业务层处理了查询和添加评论的业务逻辑;而在表现层,通过Controller和Thymeleaf模板展示了评论数据,并处理了回帖的展示和添加。
摘要由CSDN通过智能技术生成

显示评论

数据层

记得先写实体类

  • 根据实体查询一页评论数据
   // 查询全部的评论并对其实现分页
   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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值