当前位置: 首页 > news >正文

模板建站seo优化/沧州网站seo

模板建站seo优化,沧州网站seo,济南 网站建设,自己做的网站怎么实现结算功能先编辑数据访问层dao 在messagemapper中添加: // 查询某个主题下最新的通知 Message selectLatestNotice(int userId, String topic);// 查询某个主题所包含的通知数量 int selectNoticeCount(int userId, String topic);// 查询未读的通知的数量 int selectNotic…

在这里插入图片描述
先编辑数据访问层dao

在messagemapper中添加:

// 查询某个主题下最新的通知
Message selectLatestNotice(int userId, String topic);

在这里插入图片描述

// 查询某个主题所包含的通知数量
int selectNoticeCount(int userId, String topic);

在这里插入图片描述

// 查询未读的通知的数量
int selectNoticeUnreadCount(int userId, String topic);

在这里插入图片描述

打开MessageMapper.xml

查到最新的通知:

<select id="selectLatestNotice" resultType="Message">select <include refid="selectFields"></include>from messagewhere id in (<!-- 最终查到的是最大的id -->select max(id) from messagewhere status != 2 <!-- =2表示私信是被删除的状态 -->and from_id = 1<!-- 因为是系统发的,所以from_id一定为1 -->and to_id = #{userId}<!-- 发送给谁 -->and conversation_id = #{topic}<!-- 主题 -->)
</select>
<select id="selectNoticeCount" resultType="int"><!-- 返回类型 整数 -->select count(id) from message<!-- 查id的数量 -->where status != 2and from_id = 1and to_id = #{userId}and conversation_id = #{topic}
</select>
<select id="selectNoticeUnreadCount" resultType="int">select count(id) from messagewhere status = 0<!-- 表示未读状态-->and from_id = 1and to_id = #{userId}<if test="topic!=null">and conversation_id = #{topic}</if>
</select>

在MessageService添加:

public Message findLatestNotice(int userId, String topic) {//查询最新通知return messageMapper.selectLatestNotice(userId, topic);
}public int findNoticeCount(int userId, String topic) {return messageMapper.selectNoticeCount(userId, topic);
}public int findNoticeUnreadCount(int userId, String topic) {return messageMapper.selectNoticeUnreadCount(userId, topic);
}

在MessageController添加:

在getNoticeList类中添加:

// 查询评论类通知
Message message = messageService.findLatestNotice(user.getId(), TOPIC_COMMENT);
Map<String, Object> messageVO = new HashMap<>();
if (message != null) {messageVO.put("message", message);String content = HtmlUtils.htmlUnescape(message.getContent());//去除content中的转义字符,是正常显示的Map<String, Object> data = JSONObject.parseObject(content, HashMap.class);//得到map类型的对象 datamessageVO.put("user", userService.findUserById((Integer) data.get("userId")));//把data中的数据转存到  messageVO里messageVO.put("entityType", data.get("entityType"));messageVO.put("entityId", data.get("entityId"));messageVO.put("postId", data.get("postId"));//帖子id//某一类通知总的数量int count = messageService.findNoticeCount(user.getId(), TOPIC_COMMENT);messageVO.put("count", count);//未读的数量int unread = messageService.findNoticeUnreadCount(user.getId(), TOPIC_COMMENT);messageVO.put("unread", unread);
}
model.addAttribute("commentNotice", messageVO);//接下来把messageVO 传给模板// 查询点赞类通知
message = messageService.findLatestNotice(user.getId(), TOPIC_LIKE);
messageVO = new HashMap<>();
if (message != null) {messageVO.put("message", message);String content = HtmlUtils.htmlUnescape(message.getContent());Map<String, Object> data = JSONObject.parseObject(content, HashMap.class);messageVO.put("user", userService.findUserById((Integer) data.get("userId")));messageVO.put("entityType", data.get("entityType"));messageVO.put("entityId", data.get("entityId"));messageVO.put("postId", data.get("postId"));int count = messageService.findNoticeCount(user.getId(), TOPIC_LIKE);messageVO.put("count", count);int unread = messageService.findNoticeUnreadCount(user.getId(), TOPIC_LIKE);messageVO.put("unread", unread);
}
model.addAttribute("likeNotice", messageVO);// 查询关注类通知
message = messageService.findLatestNotice(user.getId(), TOPIC_FOLLOW);
messageVO = new HashMap<>();
if (message != null) {messageVO.put("message", message);String content = HtmlUtils.htmlUnescape(message.getContent());Map<String, Object> data = JSONObject.parseObject(content, HashMap.class);messageVO.put("user", userService.findUserById((Integer) data.get("userId")));messageVO.put("entityType", data.get("entityType"));messageVO.put("entityId", data.get("entityId"));//关注不需要postid,只提示:某某某关注了你int count = messageService.findNoticeCount(user.getId(), TOPIC_FOLLOW);messageVO.put("count", count);int unread = messageService.findNoticeUnreadCount(user.getId(), TOPIC_FOLLOW);messageVO.put("unread", unread);
}
model.addAttribute("followNotice", messageVO);

接下来显示这两部分

在这里插入图片描述

// 查询未读消息数量
int letterUnreadCount = messageService.findLetterUnreadCount(user.getId(), null);//不关注某一特定会话,而是所有会话,所以此处为null
model.addAttribute("letterUnreadCount", letterUnreadCount);
int noticeUnreadCount = messageService.findNoticeUnreadCount(user.getId(), null);//不关注某一特定主题,而是所有主题,所以此处为null
model.addAttribute("noticeUnreadCount", noticeUnreadCount);return "/site/notice";

打开letter.html

<!-- 通知列表 -->
<ul class="list-unstyled"><!--评论类通知--><li class="media pb-3 pt-3 mb-3 border-bottom position-relative" th:if="${commentNotice.message!=null}"><span class="badge badge-danger" th:text="${commentNotice.unread!=0?commentNotice.unread:''}">3</span><!--commentNotice.unread!=0 则显示  unread--><img src="http://static.nowcoder.com/images/head/reply.png" class="mr-4 user-header" alt="通知图标"><div class="media-body"><h6 class="mt-0 mb-3"><span>评论</span><span class="float-right text-muted font-size-12"th:text="${#dates.format(commentNotice.message.createTime,'yyyy-MM-dd HH:mm:ss')}">2019-04-28 14:13:25</span></h6><div><a th:href="@{/notice/detail/comment}">用户<i th:utext="${commentNotice.user.username}">nowcoder</i><!--用户名字 -->评论了你的<b th:text="${commentNotice.entityType==1?'帖子':'回复'}">帖子</b> ...<!--根据entityType,判断是回复还是帖子--></a><ul class="d-inline font-size-12 float-right"><li class="d-inline ml-2"><span class="text-primary"><i th:text="${commentNotice.count}">3</i> 条会话</span></li></ul></div></div></li><!--点赞类通知--><li class="media pb-3 pt-3 mb-3 border-bottom position-relative" th:if="${likeNotice.message!=null}"><span class="badge badge-danger" th:text="${likeNotice.unread!=0?likeNotice.unread:''}">3</span><!--likeNotice.unread!=则显示unread,否则什么也不显示,即 ''--><img src="http://static.nowcoder.com/images/head/like.png" class="mr-4 user-header" alt="通知图标"><div class="media-body"><h6 class="mt-0 mb-3"><span></span><span class="float-right text-muted font-size-12"th:text="${#dates.format(likeNotice.message.createTime,'yyyy-MM-dd HH:mm:ss')}">2019-04-28 14:13:25</span></h6><div><a th:href="@{/notice/detail/like}">用户<i th:utext="${likeNotice.user.username}">nowcoder</i>点赞了你的<b th:text="${likeNotice.entityType==1?'帖子':'回复'}">帖子</b> ...</a><ul class="d-inline font-size-12 float-right"><li class="d-inline ml-2"><span class="text-primary"><i th:text="${likeNotice.count}">3</i> 条会话</span></li></ul></div></div></li><!--关注类通知--><li class="media pb-3 pt-3 mb-3 border-bottom position-relative" th:if="${followNotice.message!=null}"><span class="badge badge-danger" th:text="${followNotice.unread!=0?followNotice.unread:''}">3</span><img src="http://static.nowcoder.com/images/head/follow.png" class="mr-4 user-header" alt="通知图标"><div class="media-body"><h6 class="mt-0 mb-3"><span>关注</span><span class="float-right text-muted font-size-12"th:text="${#dates.format(followNotice.message.createTime,'yyyy-MM-dd HH:mm:ss')}">2019-04-28 14:13:25</span></h6><div><a th:href="@{/notice/detail/follow}">用户<i th:utext="${followNotice.user.username}">nowcoder</i>关注了你 ...</a><ul class="d-inline font-size-12 float-right"><li class="d-inline ml-2"><span class="text-primary"><i th:text="${followNotice.count}">3</i> 条会话</span></li>

测试:

登录后,
在这里插入图片描述

查看消息:

在这里插入图片描述

下面开发通知详情:

在MessageMapper接口中添加

// 查询某个主题所包含的通知列表
List<Message> selectNotices(int userId, String topic, int offset, int limit);

在MessageMapper.xml中,查询:

<select id="selectNotices" resultType="Message">select <include refid="selectFields"></include>from messagewhere status != 2and from_id = 1and to_id = #{userId}and conversation_id = #{topic}order by create_time desc<!-- 倒序排列-->limit #{offset}, #{limit}
</select>

在业务层MessageService中

public List<Message> findNotices(int userId, String topic, int offset, int limit) {return messageMapper.selectNotices(userId, topic, offset, limit);
}

视图层

在messagecontroller中

@RequestMapping(path = "/notice/detail/{topic}", method = RequestMethod.GET)
public String getNoticeDetail(@PathVariable("topic") String topic, Page page, Model model) {//@PathVariable("topic") 得到路径中的Variable;声明page参数以分页;给模板model传数据User user = hostHolder.getUser();//获取当前用户page.setLimit(5);//设置分页条件,每页五条数据page.setPath("/notice/detail/" + topic);page.setRows(messageService.findNoticeCount(user.getId(), topic));//行数List<Message> noticeList = messageService.findNotices(user.getId(), topic, page.getOffset(), page.getLimit());List<Map<String, Object>> noticeVoList = new ArrayList<>();if (noticeList != null) {for (Message notice : noticeList) {Map<String, Object> map = new HashMap<>();// 通知map.put("notice", notice);// 内容String content = HtmlUtils.htmlUnescape(notice.getContent());//将内容转义处理Map<String, Object> data = JSONObject.parseObject(content, HashMap.class);map.put("user", userService.findUserById((Integer) data.get("userId")));map.put("entityType", data.get("entityType"));map.put("entityId", data.get("entityId"));map.put("postId", data.get("postId"));// 通知作者map.put("fromUser", userService.findUserById(notice.getFromId()));noticeVoList.add(map);}}model.addAttribute("notices", noticeVoList);
// 设置已读
List<Integer> ids = getLetterIds(noticeList);//获取需要设置已读的id
if (!ids.isEmpty()) {messageService.readMessage(ids);
}return "/site/notice-detail";//返回模板

设置返回模板:
编辑
notice.detail.html

<!-- 通知列表 --><ul class="list-unstyled mt-4"><li class="media pb-3 pt-3 mb-2" th:each="map:${notices}"><img th:src="${map.fromUser.headerUrl}" class="mr-4 rounded-circle user-header" alt="系统图标"><div class="toast show d-lg-block" role="alert" aria-live="assertive" aria-atomic="true"><div class="toast-header"><strong class="mr-auto" th:utext="${map.fromUser.username}">落基山脉下的闲人</strong><small th:text="${#dates.format(map.notice.createTime,'yyyy-MM-dd HH:mm:ss')}">2019-04-25 15:49:32</small><button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close"><span aria-hidden="true">&times;</span></button></div><div class="toast-body"><span th:if="${topic.equals('comment')}"><!-- 判断是否等于comment -->用户<i th:utext="${map.user.username}">nowcoder</i>评论了你的<b th:text="${map.entityType==1?'帖子':'回复'}">帖子</b>,<a class="text-primary" th:href="@{|/discuss/detail/${map.postId}|}">点击查看</a> !</span><span th:if="${topic.equals('like')}">用户<i th:utext="${map.user.username}">nowcoder</i>点赞了你的<b th:text="${map.entityType==1?'帖子':'回复'}">帖子</b>,<a class="text-primary" th:href="@{|/discuss/detail/${map.postId}|}">点击查看</a> !</span><span th:if="${topic.equals('follow')}">用户<i th:utext="${map.user.username}">nowcoder</i>关注了你,<a class="text-primary" th:href="@{|/user/profile/${map.user.id}|}">点击查看</a> !</span></div></div></li></ul><!-- 分页 --><nav class="mt-5" th:replace="index::pagination"><ul class="pagination justify-content-center"><li class="page-item"><a class="page-link" href="#">首页</a></li><li class="page-item disabled"><a class="page-link" href="#">上一页</a></li><li class="page-item active"><a class="page-link" href="#">1</a></li><li class="page-item"><a class="page-link" href="#">2</a></li><li class="page-item"><a class="page-link" href="#">3</a></li><li class="page-item"><a class="page-link" href="#">4</a></li><li class="page-item"><a class="page-link" href="#">5</a></li><li class="page-item"><a class="page-link" href="#">下一页</a></li><li class="page-item"><a class="page-link" href="#">末页</a></li></ul></nav></div></div>

重新编译:

在这里插入图片描述
显示了评论的数据:
在这里插入图片描述
点击 点击查看,能链接到 帖子详情
在这里插入图片描述
在这里插入图片描述
共20条
在这里插入图片描述
此时,未读消息清零
在这里插入图片描述
现在还有未读消息 数量未处理。
应该是a=b+c
在这里插入图片描述
所以要新写一个拦截器,MessageInterceptor

package com.nowcoder.community.controller.interceptor;import com.nowcoder.community.entity.User;
import com.nowcoder.community.service.MessageService;
import com.nowcoder.community.util.HostHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;@Component//交给容器来管理
public class MessageInterceptor implements HandlerInterceptor {@Autowiredprivate HostHolder hostHolder;//当前用户@Autowiredprivate MessageService messageService;@Overridepublic void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {User user = hostHolder.getUser();//查user的未读消息数量if (user != null && modelAndView != null) {//user != null查之前判断 有无登录, 没有登录就不需要查int letterUnreadCount = messageService.findLetterUnreadCount(user.getId(), null);//私信未读数量int noticeUnreadCount = messageService.findNoticeUnreadCount(user.getId(), null);//通知未读数量modelAndView.addObject("allUnreadCount", letterUnreadCount + noticeUnreadCount);//allUnreadCount 总的未读数量}}
}

打开拦截器配置文件:webmvcconfig
注入刚刚写好的拦截器:

@Autowired
private MessageInterceptor messageInterceptor;

添加这一句话:

registry.addInterceptor(messageInterceptor).excludePathPatterns("/**/*.css", "/**/*.js", "/**/*.png", "/**/*.jpg", "/**/*.jpeg");

在index.html中第30页

<a class="nav-link position-relative" th:href="@{/letter/list}">消息<span class="badge badge-danger" th:text="${allUnreadCount!=0?allUnreadCount:''}">12</span></a><!-- 不为0则显示allUnreadCount,为0则显示空值 -->

测试:
在这里插入图片描述

http://www.lbrq.cn/news/797149.html

相关文章:

  • 金溪那里可以做网站/青岛seo经理
  • 基于工作过程的商务网站建设 网页制作/济南百度竞价代运营
  • 好的做问卷调查的网站好/网站友情链接是什么
  • app软件开发培训班/微信seo是什么意思
  • 网站备案需要去哪办理/广告投放网
  • 没有公司可以做网站吗/如何做网络推广运营
  • 网站建设php/哪个平台可以接推广任务
  • 小型网站建设/seo优化关键词排名
  • 宿迁做网站 宿迁网站建设/seo是什么职业做什么的
  • 网站建设创作思路怎么写/360竞价推广登录入口
  • 电子商务网站建设书籍/域名
  • 酒店网站建设描述/chrome浏览器
  • 上海品牌型网站建设靠谱/汕头网站建设公司
  • 公司网站怎么做才能吸引人/免费行情软件网站下载大全
  • 山东省环保厅官方网站建设项目/百度前三推广
  • 时时彩 网站开发/郑州网站制作公司哪家好
  • 网站建设的设备/杭州企业seo
  • 万网主机网站建设数据库怎么弄/seo排名优化教程
  • 数据库做网站/广东短视频seo搜索哪家好
  • 局网站建设进入前十名/有免费推广平台
  • c 网站开发 调试/seo排名的影响因素有哪些
  • 电子商务他们的代表网站/济南网站建设方案
  • 域名访问网站应该怎么做/seo专业技术培训
  • 做拍卖的网站有哪些/品牌宣传方式
  • 鲜花网站建设项目概述/衡阳有实力seo优化
  • 网页网站导读怎么做/太原seo公司
  • 常见c2c网站有哪些/谷歌sem服务商
  • 昆明做网站建设技巧公司/网络宣传渠道有哪些
  • wordpress的配置文件/好搜自然seo
  • 上海徽与章网站建设宗旨/网站如何快速被百度收录
  • Ubuntu22.4部署大模型前置安装
  • JAVA国际版同城服务同城信息同城任务发布平台APP源码Android + IOS
  • 原生JS使用svg-pan-zoom库平移和缩放svg
  • String boot 接入 azure云TTS
  • 社群团购市场选择与开源技术赋能下的下沉市场开拓策略研究——以开源AI智能名片、链动2+1模式与S2B2C商城小程序为例
  • 超越 ChatGPT:智能体崛起,开启全自主 AI 时代