国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當前位置: 首頁 > news >正文

用凡科做網(wǎng)站可靠嗎外國網(wǎng)站怎么進入

用凡科做網(wǎng)站可靠嗎,外國網(wǎng)站怎么進入,c .net網(wǎng)站開發(fā),網(wǎng)站建設?首選百川互動顯示評論 數(shù)據(jù)庫 entity_type代表評論的目標類型,評論帖子和評論評論 entity_id代表評論的目標id,具體是哪個帖子/評論 targer_id代表評論指向哪個人 entity public class Comment {private int id;private int userId;private int entityType;priv…

顯示評論

數(shù)據(jù)庫

entity_type代表評論的目標類型,評論帖子和評論評論

entity_id代表評論的目標id,具體是哪個帖子/評論

targer_id代表評論指向哪個人

entity

public class Comment {private int id;private int userId;private int entityType;private int entityId;private int targetId;private String content;private int status;private Date createTime;}

mapper

根據(jù)實體查詢一頁評論數(shù)據(jù)

根據(jù)實體查詢評論的數(shù)量(為了分頁)

@Mapper
public interface CommentMapper {List<Comment> selectCommentsByEntity(int entityType, int entityId, int offset, int limit);int selectCountByEntity(int entityType, int entityId);}
    <select id="selectCommentsByEntity" resultType="Comment">select <include refid="selectFields"></include>from commentwhere status = 0and entity_type = #{entityType}and entity_id = #{entityId}order by create_time asclimit #{offset}, #{limit}</select><select id="selectCountByEntity" resultType="int">select count(id)from commentwhere status = 0and entity_type = #{entityType}and entity_id = #{entityId}</select>

service

處理查詢評論的業(yè)務

處理查詢評論數(shù)量的業(yè)務

@Service
public class CommentService implements CommunityConstant {@Autowiredprivate CommentMapper commentMapper;public List<Comment> findCommentsByEntity(int entityType, int entityId, int offset, int limit) {return commentMapper.selectCommentsByEntity(entityType, entityId, offset, limit);}public int findCommentCount(int entityType, int entityId) {return commentMapper.selectCountByEntity(entityType, entityId);}}

controller

查詢回復,查詢回復數(shù)量是在查看帖子的時候進行的,所以修改discussPostController里面的getDiscussPost函數(shù)就可以

顯示帖子詳細數(shù)據(jù)時,同時顯示該帖子所有的評論數(shù)據(jù)

    @RequestMapping(path = "/detail/{discussPostId}", method = RequestMethod.GET)public String getDiscussPost(@PathVariable("discussPostId") int discussPostId, Model model, Page page) {// 帖子DiscussPost post = discussPostService.findDiscussPostById(discussPostId);model.addAttribute("post", post);// 作者User user = userService.findUserById(post.getUserId());model.addAttribute("user", user);// 評論分頁信息page.setLimit(5);page.setPath("/discuss/detail/" + discussPostId);// 直接在帖子里面取了page.setRows(post.getCommentCount());// 評論: 給帖子的評論// 回復: 給評論的評論// 評論列表,得到當前帖子的所有評論List<Comment> commentList = commentService.findCommentsByEntity(ENTITY_TYPE_POST, post.getId(), page.getOffset(), page.getLimit());// 評論VO列表,VO-》view objectList<Map<String, Object>> commentVoList = new ArrayList<>();if (commentList != null) {for (Comment comment : commentList) {// 評論VOMap<String, Object> commentVo = new HashMap<>();// 評論commentVo.put("comment", comment);// 作者commentVo.put("user", userService.findUserById(comment.getUserId()));// 回復列表,不搞分頁List<Comment> replyList = commentService.findCommentsByEntity(ENTITY_TYPE_COMMENT, comment.getId(), 0, Integer.MAX_VALUE);// 回復VO列表List<Map<String, Object>> replyVoList = new ArrayList<>();if (replyList != null) {for (Comment reply : replyList) {Map<String, Object> replyVo = new HashMap<>();// 回復replyVo.put("reply", reply);// 作者replyVo.put("user", userService.findUserById(reply.getUserId()));// 回復目標User target = reply.getTargetId() == 0 ? null : userService.findUserById(reply.getTargetId());replyVo.put("target", target);replyVoList.add(replyVo);}}commentVo.put("replys", replyVoList);// 回復數(shù)量int replyCount = commentService.findCommentCount(ENTITY_TYPE_COMMENT, comment.getId());commentVo.put("replyCount", replyCount);commentVoList.add(commentVo);}}model.addAttribute("comments", commentVoList);return "/site/discuss-detail";}

前端

index

<ul class="d-inline float-right"><li class="d-inline ml-2">贊 11</li><li class="d-inline ml-2">|</li><li class="d-inline ml-2">回帖 <span th:text="${map.post.commentCount}">7</span></li>
</ul>

?discuss-detail

這個改的有點多,但是估計不會問前端的東西

增加評論

mapper

增加評論數(shù)據(jù)

@Mapper
public interface CommentMapper {int insertComment(Comment comment);}
    <insert id="insertComment" parameterType="Comment">insert into comment(<include refid="insertFields"></include>)values(#{userId},#{entityType},#{entityId},#{targetId},#{content},#{status},#{createTime})</insert>

?修改帖子的評論數(shù)量

@Mapper
public interface DiscussPostMapper {int updateCommentCount(int id, int commentCount);}
    <update id="updateCommentCount">update discuss_post set comment_count = #{commentCount} where id = #{id}</update>

service

處理添加評論的業(yè)務

CommentService

    @Transactional(isolation = Isolation.READ_COMMITTED, propagation = Propagation.REQUIRED)public int addComment(Comment comment) {if (comment == null) {throw new IllegalArgumentException("參數(shù)不能為空!");}// 添加評論comment.setContent(HtmlUtils.htmlEscape(comment.getContent()));comment.setContent(sensitiveFilter.filter(comment.getContent()));int rows = commentMapper.insertComment(comment);// 更新帖子評論數(shù)量if (comment.getEntityType() == ENTITY_TYPE_POST) {int count = commentMapper.selectCountByEntity(comment.getEntityType(), comment.getEntityId());discussPostService.updateCommentCount(comment.getEntityId(), count);}return rows;}

先增加評論,再更新帖子的評論數(shù)量

DiscussPostService

    public int updateCommentCount(int id, int commentCount) {return discussPostMapper.updateCommentCount(id, commentCount);}

controller

處理添加評論數(shù)據(jù)的請求

設置添加評論的表單

@Controller
@RequestMapping("/comment")
public class CommentController {@Autowiredprivate CommentService commentService;@Autowiredprivate HostHolder hostHolder;@RequestMapping(path = "/add/{discussPostId}", method = RequestMethod.POST)public String addComment(@PathVariable("discussPostId") int discussPostId, Comment comment) {comment.setUserId(hostHolder.getUser().getId());comment.setStatus(0);comment.setCreateTime(new Date());commentService.addComment(comment);return "redirect:/discuss/detail/" + discussPostId;}}

前端

評論

<!-- 回帖輸入 --><div class="container mt-3"><form class="replyform" method="post" th:action="@{|/comment/add/${post.id}|}"><p class="mt-3"><a name="replyform"></a><textarea placeholder="在這里暢所欲言你的看法吧!" name="content"></textarea><input type="hidden" name="entityType" value="1"><input type="hidden" name="entityId" th:value="${post.id}"></p><p class="text-right"><button type="submit" class="btn btn-primary btn-sm">&nbsp;&nbsp;回&nbsp;&nbsp;帖&nbsp;&nbsp;</button></p></form></div>

回復

<!-- 回復輸入框 --><li class="pb-3 pt-3"><form method="post" th:action="@{|/comment/add/${post.id}|}"><div><input type="text" class="input-size" name="content" placeholder="請輸入你的觀點"/><input type="hidden" name="entityType" value="2"><input type="hidden" name="entityId" th:value="${cvo.comment.id}"></div><div class="text-right mt-2"><button type="submit" class="btn btn-primary btn-sm" onclick="#">&nbsp;&nbsp;回&nbsp;&nbsp;復&nbsp;&nbsp;</button></div></form></li>
										<div th:id="|huifu-${rvoStat.count}|" class="mt-4 collapse"><form method="post" th:action="@{|/comment/add/${post.id}|}"><div><input type="text" class="input-size" name="content" th:placeholder="|回復${rvo.user.username}|"/><input type="hidden" name="entityType" value="2"><input type="hidden" name="entityId" th:value="${cvo.comment.id}"><input type="hidden" name="targetId" th:value="${rvo.user.id}"></div><div class="text-right mt-2"><button type="submit" class="btn btn-primary btn-sm" onclick="#">&nbsp;&nbsp;回&nbsp;&nbsp;復&nbsp;&nbsp;</button></div></form></div>

http://aloenet.com.cn/news/46970.html

相關文章:

  • 網(wǎng)站 f型軟文營銷的案例
  • 如何做酒店網(wǎng)站設計uc瀏覽器關鍵詞排名優(yōu)化
  • 揚州高郵網(wǎng)站建設上海網(wǎng)站建設哪家好
  • 南江縣建設局網(wǎng)站企業(yè)線上培訓平臺有哪些
  • 網(wǎng)站關鍵詞排名全掉了seo優(yōu)化大公司排名
  • 照明網(wǎng)站建設新媒體
  • 公眾號做電影網(wǎng)站營銷伎巧第一季
  • 東莞網(wǎng)絡優(yōu)化哪家強seo排名點擊軟件運營
  • 家居網(wǎng)站建設的需求分析今日新聞簡報
  • 安吉城鄉(xiāng)建設局網(wǎng)站百度推廣登陸網(wǎng)址
  • 聊城網(wǎng)站改版搜索引擎營銷與seo優(yōu)化
  • 成人版嗶哩嗶哩bilibili邢臺市seo服務
  • 網(wǎng)站建設專業(yè)簡介優(yōu)化營商環(huán)境心得體會個人
  • 青田網(wǎng)站做服裝找工作aso優(yōu)化貼吧
  • 六安哪家做網(wǎng)站好什么平臺打廣告比較好免費的
  • 怎么用jsp做網(wǎng)站b站黃頁推廣
  • 中國建設行業(yè)網(wǎng)黑帽seo什么意思
  • 郴州新網(wǎng)最新招聘信息奉節(jié)縣關鍵詞seo排名優(yōu)化
  • 建設網(wǎng)站的公司要什么資質(zhì)百度官網(wǎng)認證申請
  • 免費域名網(wǎng)站建設站長之家域名解析
  • 設計網(wǎng)站推薦室內(nèi)排名優(yōu)化方案
  • 寶塔 wordpress 404蘭州seo公司
  • 女性時尚網(wǎng)站模板鄒平縣seo網(wǎng)頁優(yōu)化外包
  • 廣東工程建設監(jiān)理有限公司網(wǎng)站石家莊關鍵詞優(yōu)化報價
  • 網(wǎng)站開發(fā)的基本技術業(yè)務推廣方式有哪些
  • 網(wǎng)站開發(fā)定制多少錢南京百度搜索優(yōu)化
  • 廣州城市建設網(wǎng)站宣傳推廣渠道有哪些
  • 商業(yè)廣告創(chuàng)意設計seo關鍵詞推廣怎么做
  • 全國企業(yè)信用信息平臺武漢整站優(yōu)化
  • 提供衡水網(wǎng)站建設深圳網(wǎng)站建設方案