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

建设网站需要的安全设备什么样的网站是一个成功的网站

建设网站需要的安全设备,什么样的网站是一个成功的网站,asp.net 网站图标,商标设计一个目录 1.私信列表 1.1 数据访问层 1.2 业务层 1.3 表现层 1.4 私信详情 2.发送列表 2.1 数据访问层 2.2 业务层 2.3 表现层 2.4 设置已读状态 1.私信列表 私信列表#xff1a;查询当前用户的会话列表#xff0c;每个会话只显示一条最新的私信、支持分页列表私信详情…目录 1.私信列表 1.1 数据访问层 1.2 业务层 1.3 表现层 1.4 私信详情 2.发送列表 2.1 数据访问层 2.2 业务层 2.3 表现层 2.4 设置已读状态  1.私信列表 私信列表查询当前用户的会话列表每个会话只显示一条最新的私信、支持分页列表私信详情查询某个会话所包含的私信、支持分页显示 在 entity 包下新建 Message 实体类 package com.example.demo.entity;import java.util.Date; /*** 私信列表实体类*/ public class Message {private int id;private int fromId;private int toId;private String conversationId;//会话 idprivate String content;private int status;private Date createTime;public int getId() {return id;}public void setId(int id) {this.id id;}public int getFromId() {return fromId;}public void setFromId(int fromId) {this.fromId fromId;}public int getToId() {return toId;}public void setToId(int toId) {this.toId toId;}public String getConversationId() {return conversationId;}public void setConversationId(String conversationId) {this.conversationId conversationId;}public String getContent() {return content;}public void setContent(String content) {this.content content;}public int getStatus() {return status;}public void setStatus(int status) {this.status status;}public Date getCreateTime() {return createTime;}public void setCreateTime(Date createTime) {this.createTime createTime;}Overridepublic String toString() {return Message{ id id , fromId fromId , toId toId , conversationId conversationId \ , content content \ , status status , createTime createTime };} } 1.1 数据访问层 在 dao 包下创建 MessageMapper 接口 查询当前用户的会话列表,针对每个会话只返回一条最新的私信根据用户id查询并且支持分页功能查询当前用户的会话数量根据用户 id 查询查询某个会话所包含的私信列表根据会话 id 查询并且支持分页功能查询某个会话所包含的私信数量根据会话 id 查询查询未读私信的数量根据用户 id 和 会话 id查询会话 id 动态拼接 package com.example.demo.dao;import com.example.demo.entity.Message;import java.util.List;/*** 私信列表数据访问层逻辑*/ public interface MessageMapper {//查询当前用户的会话列表,针对每个会话只返回一条最新的私信ListMessage selectConversations(int userId, int offset, int limit);//查询当前用户的会话数量int selectConversationCount(int userId);//查询某个会话所包含的私信列表ListMessage selectLetters(String conversationId, int offset, int limit);//查询某个会话所包含的私信数量int selectLetterCount(String conversationId);//查询未读私信的数量int selectLetterUnreadCount(int userId, String conversationId); } 在 resources 资源文件下的 mapper 中添加配置文件message-mapper ?xml version1.0 encodingUTF-8 ? !DOCTYPE mapperPUBLIC -//mybatis.org//DTD Mapper 3.0//ENhttp://mybatis.org/dtd/mybatis-3-mapper.dtd mapper namespacecom.example.demo.dao.MessageMapper!---私信列表配置文件--!--公用 sql--sql idselectFieldsid, from_id, to_id, conversation_id, content, status, create_time/sql!--查询当前用户的会话列表--select idselectConversations resultTypeMessageselect include refidselectFields/includefrom messagewhere id in (select max(id) from messagewhere status ! 2and from_id ! 1and (from_id #{userId} or to_id #{userId})group by conversation_id)order by id desclimit #{offset}, #{limit}/select!--查询当前用户的会话数量--select idselectConversationCount resultTypeintselect count(m.maxid) from (select max(id) as maxid from messagewhere status ! 2and from_id ! 1and (from_id #{userId} or to_id #{userId})group by conversation_id) as m/select!--查询某个会话所包含的私信列表--select idselectLetters resultTypeMessageselect include refidselectFields/includefrom messagewhere status ! 2and from_id ! 1and conversation_id #{conversationId}order by id desclimit #{offset}, #{limit}/select!--查询某个会话所包含的私信数量--select idselectLetterCount resultTypeintselect count(id)from messagewhere status ! 2and from_id ! 1and conversation_id #{conversationId}/select!--查询未读私信的数量--select idselectLetterUnreadCount resultTypeintselect count(id)from messagewhere status 0and from_id ! 1and to_id #{userId}if testconversationId!nulland conversation_id #{conversationId}/if/select/mapper 1.2 业务层 在 service 包下新建 MessageService 类业务查询 定义五个方法调用 Mapper实现业务即可注入 MessageMapper package com.example.demo.service;import com.example.demo.dao.MessageMapper; import com.example.demo.entity.Message; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service;import java.util.List;/*** 私信列表业务组件*/ Service public class MessageService {Autowiredprivate MessageMapper messageMapper;//查询当前用户的会话列表public ListMessage findConversations(int userId, int offset, int limit) {return messageMapper.selectConversations(userId, offset, limit);}//查询当前用户的会话数量public int findConversationCount(int userId) {return messageMapper.selectConversationCount(userId);}//查询某个会话所包含的私信列表public ListMessage findLetters(String conversationId, int offset, int limit) {return messageMapper.selectLetters(conversationId, offset, limit);}//查询某个会话所包含的私信数量public int findLetterCount(String conversationId) {return messageMapper.selectLetterCount(conversationId);}//查询未读私信的数量public int findLetterUnreadCount(int userId, String conversationId) {return messageMapper.selectLetterUnreadCount(userId, conversationId);} } 1.3 表现层 在 controller 类下新建 MessageController 类处理私信详情请求 添加处理私信列表的方法声明私信路径请求为 GET 请求传入 Model、分页 Page实现查询功能注入 MessageService查询当前用户私信用户注入 HostHolder设置分页信息每页显示多少条数据、分页路径、一共多少条数据——查询当前会话的数据、传入 userId需要获取 User查询会话列表得到数据显示未读数量、每一次会话的未读数量、会话中包含多少条数据 声明集合用 Map 封装将多个数据存入 Map 中遍历列表新建 HashMap 重构数据存入遍历的每一次数据、存入未读详细数据用户 id、会话 id、存入多少条数量会话 id、显示当前用户相对应的用户头像寻找目标 id如果当前用户是消息的发起者目标就是接收人如果当前对象是消息的接收者目标就是发起者将目标对象存入 HashMap 中注入 UserService将得到的 HashMap 存入集合当中最后传入模板中 查询未读消息数量查询整个用户所有的未读消息数量传入 Model 中显示返回 Model 路径/site/letter package com.example.demo.controller;import com.example.demo.entity.Message; import com.example.demo.entity.Page; import com.example.demo.entity.User; import com.example.demo.service.MessageService; import com.example.demo.service.UserService; import com.example.demo.util.HostHolder; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod;import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;/*** 私信列表表现层*/ Controller public class MessageController {//实现查询功能注入 MessageServiceAutowiredprivate MessageService messageService;//查询当前用户私信用户注入 HostHolderAutowiredprivate HostHolder hostHolder;Autowiredprivate UserService userService;//添加处理私信列表的方法RequestMapping(path /letter/list, method RequestMethod.GET)public String getLetterList(Model model, Page page) {//设置分页信息每页显示多少条数据、分页路径、一共多少条数据——查询当前会话的数据、传入 userId需要获取 UserUser user hostHolder.getUser();page.setLimit(5);page.setPath(/letter/list);page.setRows(messageService.findConversationCount(user.getId()));//查询会话列表得到数据(显示未读数量、每一次会话的未读数量、会话中包含多少条数据)//声明集合用 Map 封装将多个数据存入 Map 中ListMessage conversationList messageService.findConversations(user.getId(), page.getOffset(), page.getLimit());ListMapString, Object conversations new ArrayList();//遍历列表新建 HashMap 重构数据存入遍历的每一次数据、存入未读详细数据用户 id、会话 id// 、存入多少条数量会话 id、显示当前用户相对应的用户头像if (conversationList ! null) {for (Message message : conversationList) {MapString, Object map new HashMap();map.put(conversation, message);map.put(letterCount, messageService.findLetterCount(message.getConversationId()));map.put(unreadCount, messageService.findLetterUnreadCount(user.getId(), message.getConversationId()));//寻找目标 id如果当前用户是消息的发起者目标就是接收人如果当前对象是消息的接收者目标就是发起者int targetId user.getId() message.getFromId() ? message.getToId() : message.getFromId();//将目标对象存入 HashMap 中注入 UserServicemap.put(target, userService.findUserById(targetId));//将得到的 HashMap 存入集合当中conversations.add(map);}}//最后传入模板中model.addAttribute(conversations, conversations);// 查询未读消息数量查询整个用户所有的未读消息数量传入 Model 中显示返回 Model 路径/site/letterint letterUnreadCount messageService.findLetterUnreadCount(user.getId(), null);model.addAttribute(letterUnreadCount, letterUnreadCount);return /site/letter;} } 1.4 私信详情 在 controller 类下 MessageController 类添加私信详情方法 声明访问路径点击按钮查看会话详情需要传入会话 id在路径中包含会话 id查询方法为 GET 请求方法中获取路径中的会话 id 参数并且支持分页把模板传入设置分页信息每页显示多少条数据、分页路径、行数定义私信列表分页查询会话 id、分页用集合表示Message 封装 对发信人进行补充声明集合存放 Map遍历集合实例化 HashMap然后放入私信把 fromId 转化为 fromUser将 Map 放入集合中将集合发送给模板 补充上述的来自某个人的私信当前登陆用户与之对话目标的名字查询当前登录与之对话的用户显示出来创建私有方法传入 会话 id拆封会话 id与当前用户进行判断查询私信目标返回模板 //添加私信详情方法//声明访问路径点击按钮查看会话详情需要传入会话 id在路径中包含会话 id查询方法为 GET 请求RequestMapping(path /letter/detail/{conversationId}, method RequestMethod.GET)//方法中获取路径中的会话 id 参数并且支持分页把模板传入public String getLetterDetail(PathVariable(conversationId) String conversationId, Page page, Model model) {//设置分页信息每页显示多少条数据、分页路径、行数page.setLimit(5);page.setPath(/letter/datail/ conversationId);page.setRows(messageService.findLetterCount(conversationId));//定义私信列表分页查询会话 id、分页用集合表示Message 封装ListMessage letterList messageService.findLetters(conversationId, page.getOffset(), page.getLimit());//对发信人进行补充声明集合存放 MapListMapString, Object letters new ArrayList();//遍历集合实例化 HashMap然后放入私信把 fromId 转化为 fromUser将 Map 放入集合中if (letterList ! null) {for (Message message : letterList) {MapString, Object map new HashMap();map.put(letter, message);map.put(fromUser, userService.findUserById(message.getFromId()));letters.add(map);}}model.addAttribute(letters, letters);// 私信目标——补充上述的来自某个人的私信当前登陆用户与之对话目标的名字查询当前登录与之对话的用户显示出来model.addAttribute(target, getLetterTarget(conversationId));//查询私信目标返回模板return /site/letter-detail;}//创建私有方法传入 会话 id拆封会话 id与当前用户进行判断private User getLetterTarget(String conversationId) {String[] ids conversationId.split(_);int id0 Integer.parseInt(ids[0]);int id1 Integer.parseInt(ids[1]);if (hostHolder.getUser().getId() id0) {return userService.findUserById(id1);} else {return userService.findUserById(id0);}} 2.发送列表 发送私信采用异步的方式发送私信、发送成功后刷新私信列表设置已读访问私信详情时将显示的私信设置为已读状态 2.1 数据访问层 在 dao 包下的 MessageMapper 中添加消息、修改消息的状态的方法 //新增消息int insertMessage(Message message);//修改消息的状态:修改的状态为多个id使用集合int updateStatues(ListInteger ids, int status); 在配置文件 message.xml 实现SQL !--增加消息公共 sql--sql idinsertFieldsfrom_id, to_id, conversation_id, content, status, create_time/sql!--增加消息--insert idinsertMessage parameterTypeMessage keyPropertyidinsert into message(include refidinsertFields/include)values(#{fromId},#{toId},#{conversationId},#{content},#{status},#{createTime})/insert!--修改消息的状态--update idupdateStatusupdate message set status #{status}where id inforeach collectionids itemid open( separator, close)#{id}/foreach/update 2.2 业务层 在 MessageService 中新增消息方法 过滤标签过滤敏感词在创建一个方法把消息变成已读支持一次读取多条数据使用集合 //注入敏感词Autowiredprivate SensitiveFilter sensitiveFilter;//增加消息的方法public int addMessage(Message message) {message.setContent(HtmlUtils.htmlEscape(message.getContent()));message.setContent(sensitiveFilter.filter(message.getContent()));return messageMapper.insertMessage(message);}//创建一个方法把消息变成已读支持一次读取多条数据使用集合public int readMessage(ListInteger ids) {return messageMapper.updateStatus(ids, 1);} 2.3 表现层 在 MessageController 中去写增加消息的请求方法 声明访问路径请求方式为 POST 请求提交数据异步请求添加 ResponseBody 页面表单需要传入 发私信给谁接收人用户名、私信内容通过用户名查询用户得到 id在 Userservice 添加查询方法 //通过用户名查询用户得到 idpublic User findUserByName(String username) {return userMapper.selectByName(username);} 利用当前数据构造要插入的对象从当前用户取、发送给谁、会话 id两个id使用 _ 拼接id 小的在前面、内容、当前时间做插入调用 messageService如果没报错给页面返回状态0如果报错后面统一处理异常 //发送私信的方法RequestMapping(path /letter/send, method RequestMethod.POST)ResponseBody //异步请求//页面表单需要传入 发私信给谁接收人用户名、私信内容public String sendLetter(String toName, String content) {User target userService.findUserByName(toName);if (target null) {return CommunityUtil.getJSONString(1, 目标用户不存在!);}//利用当前数据构造要插入的对象从当前用户取、发送给谁、会话 id两个id使用 _ 拼接id 小的在前面、内容、当前时间Message message new Message();message.setFromId(hostHolder.getUser().getId());message.setToId(target.getId());if (message.getFromId() message.getToId()) {message.setConversationId(message.getFromId() _ message.getToId());} else {message.setConversationId(message.getToId() _ message.getFromId());}message.setContent(content);message.setCreateTime(new Date());//做插入调用 messageServicemessageService.addMessage(message);//如果没报错给页面返回状态0;如果报错后面统一处理异常return CommunityUtil.getJSONString(0);} 前端页面 index.xml !-- 内容 --div classmaindiv classcontainerdiv classrowdiv classcol-8h6b classsquare/b 来自 i classtext-success th:utext${target.username}落基山脉下的闲人/i 的私信/h6/divdiv classcol-4 text-rightbutton typebutton classbtn btn-secondary btn-sm onclickback();返回/buttonbutton typebutton classbtn btn-primary btn-sm data-togglemodal data-target#sendModal给TA私信/button/div/div!-- 弹出框 --div classmodal fade idsendModal tabindex-1 roledialog aria-labelledbyexampleModalLabel aria-hiddentruediv classmodal-dialog modal-lg roledocumentdiv classmodal-contentdiv classmodal-headerh5 classmodal-title idexampleModalLabel发私信/h5button typebutton classclose data-dismissmodal aria-labelClosespan aria-hiddentruetimes;/span/button/divdiv classmodal-bodyformdiv classform-grouplabel forrecipient-name classcol-form-label发给/labelinput typetext classform-control idrecipient-name th:value${target.username}/divdiv classform-grouplabel formessage-text classcol-form-label内容/labeltextarea classform-control idmessage-text rows10/textarea/div/form/divdiv classmodal-footerbutton typebutton classbtn btn-secondary data-dismissmodal取消/buttonbutton typebutton classbtn btn-primary idsendBtn发送/button/div/div/div/div!-- 提示框 --div classmodal fade idhintModal tabindex-1 roledialog aria-labelledbyhintModalLabel aria-hiddentruediv classmodal-dialog modal-lg roledocumentdiv classmodal-contentdiv classmodal-headerh5 classmodal-title idhintModalLabel提示/h5/divdiv classmodal-body idhintBody发送完毕!/div/div/div/div!-- 私信列表 --ul classlist-unstyled mt-4li classmedia pb-3 pt-3 mb-2 th:eachmap:${letters}a hrefprofile.htmlimg th:src${map.fromUser.headerUrl} classmr-4 rounded-circle user-header alt用户头像 /adiv classtoast show d-lg-block rolealert aria-liveassertive aria-atomictruediv classtoast-headerstrong classmr-auto th:utext${map.fromUser.username}落基山脉下的闲人/strongsmall th:text${#dates.format(map.letter.createTime,yyyy-MM-dd HH:mm:ss)}2019-04-25 15:49:32/smallbutton typebutton classml-2 mb-1 close data-dismisstoast aria-labelClosespan aria-hiddentruetimes;/span/button/divdiv classtoast-body th:utext${map.letter.content}君不见, 黄河之水天上来, 奔流到海不复回!/div/div/li/ul!-- 分页 --nav classmt-5 th:replaceindex::paginationul classpagination justify-content-centerli classpage-itema classpage-link href#首页/a/lili classpage-item disableda classpage-link href#上一页/a/lili classpage-item activea classpage-link href#1/a/lili classpage-itema classpage-link href#2/a/lili classpage-itema classpage-link href#3/a/lili classpage-itema classpage-link href#4/a/lili classpage-itema classpage-link href#5/a/lili classpage-itema classpage-link href#下一页/a/lili classpage-itema classpage-link href#末页/a/li/ul/nav/div/div 前端页面 letter.js $(function(){$(#sendBtn).click(send_letter);$(.close).click(delete_msg); });function send_letter() {$(#sendModal).modal(hide);var toName $(#recipient-name).val();var content $(#message-text).val();$.post(CONTEXT_PATH /letter/send,{toName:toName,content:content},function(data) {data $.parseJSON(data);if(data.code 0) {$(#hintBody).text(发送成功!);} else {$(#hintBody).text(data.msg);}$(#hintModal).modal(show);setTimeout(function(){$(#hintModal).modal(hide);location.reload();}, 2000);}); }function delete_msg() {// TODO 删除数据$(this).parents(.media).remove(); } 当 xiaowen 看数据时将显示的私信设置为已读状态 2.4 设置已读状态  在 私信详情方法 补充将私信列表中未读消息提取出来自动设置为已读 在集合中提取消息补充方法传入私信列表、实例化集合遍历数据判断当前用户是否为接收者是才能去变为已读并且消息的状态是不是0 //添加私信详情方法//声明访问路径点击按钮查看会话详情需要传入会话 id在路径中包含会话 id查询方法为 GET 请求RequestMapping(path /letter/detail/{conversationId}, method RequestMethod.GET)//方法中获取路径中的会话 id 参数并且支持分页把模板传入public String getLetterDetail(PathVariable(conversationId) String conversationId, Page page, Model model) {//设置分页信息每页显示多少条数据、分页路径、行数page.setLimit(5);page.setPath(/letter/detail/ conversationId);page.setRows(messageService.findLetterCount(conversationId));//定义私信列表分页查询会话 id、分页用集合表示Message 封装ListMessage letterList messageService.findLetters(conversationId, page.getOffset(), page.getLimit());//对发信人进行补充声明集合存放 MapListMapString, Object letters new ArrayList();//遍历集合实例化 HashMap然后放入私信把 fromId 转化为 fromUser将 Map 放入集合中if (letterList ! null) {for (Message message : letterList) {MapString, Object map new HashMap();map.put(letter, message);map.put(fromUser, userService.findUserById(message.getFromId()));letters.add(map);}}model.addAttribute(letters, letters);// 私信目标——补充上述的来自某个人的私信当前登陆用户与之对话目标的名字查询当前登录与之对话的用户显示出来model.addAttribute(target, getLetterTarget(conversationId));// 设置已读ListInteger ids getLetterIds(letterList);if (!ids.isEmpty()) {messageService.readMessage(ids);}//查询私信目标返回模板return /site/letter-detail;}//在集合中提取消息private ListInteger getLetterIds(ListMessage letterList) {ListInteger ids new ArrayList();if (letterList ! null) {for (Message message : letterList) {if (hostHolder.getUser().getId() message.getToId() message.getStatus() 0) {ids.add(message.getId());}}}return ids;}
http://www.zqtcl.cn/news/460873/

相关文章:

  • js做网站福田网站设计公司
  • 郑州做网站好长春市建设工程信息网站
  • 题库网站怎么做做网站文件夹都起什么名字
  • 河南网站怎么备案东台市住房和建设局网站
  • 有什么手机做网站的asp.net网站安全
  • 怎么做查询网站后台做爰的视频网站
  • 迪虎科技网站建设国际市场那个app可以看
  • 怎么做跳转不影响原网站排名wordpress添加邮箱设置
  • 网站内容规范外贸电商怎么做
  • 郑州做网站齿轮wordpress 文章h标签美化
  • 建设银行网站怎么修改手机号码吗网站建设怎样容易
  • 网站建设风险管理计划书户外媒体网站建设免费
  • 学到什么程度可以做网站网站维护的要求包括
  • 泉州网站设计平台南阳响应式网站
  • 阿里云 企业网站选哪种推广普通话的文字内容
  • 广州市南沙建设局网站中山建网站咨询电话
  • 怎么创建网站快捷方式网络服务器搭建配置与管理 下载
  • 现在什么类型网站没有人做wordpress get_categories()
  • 石家庄网站推广优化闲鱼网络营销方式
  • 精诚时代 网站谁做的北京网站设计必看刻
  • 长沙网站排名报价企业管理培训课程网课
  • 怎样做婚庆网站外贸网站怎么注册
  • 网站设计制作公司推荐自己做商务网站有什么利弊
  • 传媒网站杨浦网站建设哪家好
  • 500m主机空间能做视频网站吗做中文网站的公司
  • 网站建设规划模板公司网站建设论文
  • p2p网站开发的内容广东世纪达建设集团有限公司官方网站
  • 网站基本建设是什么o元做网站
  • 南昌做购物网站的公司mc做弊端网站
  • 汕头制作网站推荐文化建设五大工程