[Java学习] 小型社交平台,能发帖、查看、评论、删除帖子等功能

本文介绍如何使用Java开发一个小型社交平台,实现用户可以发布、查看、评论和删除帖子的功能。通过学习这个项目,你可以深入理解Java Web开发中的关键技术和概念。
摘要由CSDN通过智能技术生成
自学去AD
小型社交平台,能发帖,查看帖子,评论帖子,删除帖子,删除评论等功能
  1. package com.iflysse.bbs.controller;
  2. import java.io.IOException;
  3. import java.io.PrintWriter;
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.List;
  7. import javax.servlet.http.HttpServletResponse;
  8. import javax.servlet.http.HttpSession;
  9. http://www.nvzi91.cn/niaodaoyan/29938.html
  10. import net.sf.json.JSONSerializer;
  11. import org.springframework.stereotype.Controller;
  12. import org.springframework.ui.ModelMap;
  13. import org.springframework.web.bind.annotation.ModelAttribute;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestMethod;
  16. import org.springframework.web.bind.annotation.SessionAttributes;
  17. import org.springframework.web.bind.support.SessionStatus;
  18. http://www.nvzi91.cn/yindaoyan/29939.html
  19. import com.alibaba.fastjson.JSON;
  20. import com.iflysse.bbs.dao.service.commentsService;
  21. import com.iflysse.bbs.dao.service.newsService;
  22. import com.iflysse.bbs.dao.service.usersService;
  23. import com.iflysse.bbs.model.comments;
  24. import com.iflysse.bbs.model.news;
  25. import com.iflysse.bbs.model.users;
  26. import com.iflysse.bbs.service.Impl.commentsServiceImpl;
  27. import com.iflysse.bbs.service.Impl.newsServiceImpl;
  28. import com.iflysse.bbs.service.Impl.usersServiceImpl;
  29. import com.sun.org.apache.xerces.internal.util.Status;
  30. @Controller
  31. @SessionAttributes({"user"})
  32. public class IndexController {
  33. @RequestMapping(value="index.do")
  34. public String index(ModelMap map){
  35. newsService ns = new newsServiceImpl();
  36. List<news> number = ns.getNews(1, Integer.MAX_VALUE);
  37. int count = number.size();
  38. int page = 0;
  39. if(count == 0){
  40. page = 1;
  41. }else{
  42. page = count%3 == 0 ? count/3 : (count/3) + 1;
  43. }http://www.nvzi91.cn/yindaoyan/29940.html
  44. List<news> lstn = ns.getNews(1, 3);
  45. map.addAttribute("page", page);
  46. map.addAttribute("index", 1);
  47. map.addAttribute("list", lstn);
  48. return "index";
  49. }
  50. @RequestMapping(value="search.do",method=RequestMethod.POST)
  51. public String search(String find, String pageIndex, ModelMap map){
  52. newsService ns = new newsServiceImpl();
  53. int index = Integer.valueOf(pageIndex);
  54. map.addAttribute("index", index);
  55. List<news> count = ns.getNews(1, Integer.MAX_VALUE);
  56. int number = count.size();
  57. int page = number%3 == 0 ? number/3 : (number/3) + 1;
  58. map.addAttribute("page", page);
  59. if (find == null) {
  60. List<news> ltn = ns.getNews(index, 3);
  61. map.addAttribute("list", ltn);
  62. } else {
  63. List<news> ltn = ns.getNewsByTitle(find, index, 3);
  64. map.addAttribute("list", ltn);
  65. }
  66. return "index";
  67. }http://www.nvzi91.cn/luanchaonanzhong/29941.html
  68. @RequestMapping(value="login.do",method=RequestMethod.GET)
  69. public String preLogin(){
  70. return "login";
  71. }
  72. http://m.nvzi91.cn/jiankang/29353.html
  73. @RequestMapping(value="login.do",method=RequestMethod.POST)
  74. public String afterLogin(String account,String password,ModelMap map){
  75. usersService us = new usersServiceImpl();
  76. users user = us.getUsersByAccPsw(account, password);
  77. if(user != null){
  78. map.addAttribute("user", user);
  79. return "redirect:index.do";
  80. }else{
  81. return "redirect:error.do";
  82. }
  83. }
  84. http://www.nvzi91.cn/zigongjiliu/29942.html
  85. @RequestMapping(value="view.do")
  86. public String vaiew(String id, ModelMap map){
  87. int newsid = Integer.valueOf(id);
  88. newsService ns = new newsServiceImpl();
  89. commentsService cs = new commentsServiceImpl();
  90. List<comments> lstc = cs.getCommentsByNewsId(newsid);
  91. news news = ns.getNewsByNewsId(newsid);
  92. map.addAttribute("news", news);
  93. map.addAttribute("comments", lstc);
  94. return "view";
  95. }http://m.nvzi91.cn/zigongai/29352.html
  96. @RequestMapping(value="comments.do")
  97. public String comment(@ModelAttribute("user")users user, String id, String content){
  98. if(user != null){
  99. int newsid = Integer.valueOf(id);
  100. comments comm = new comments(1,content,new Date(),user.getId(),newsid);
  101. commentsService cs = new commentsServiceImpl();
  102. cs.addComments(comm);
  103. return "redirect:view.do?id=" + id;
  104. }else{
  105. return "redirect:login.do";
  106. }
  107. }
  108. http://www.kmrlyy.com/fujianyan/33454.html
  109. @RequestMapping(value="error.do")
  110. public String error(){
  111. return "error";
  112. }
  113. @RequestMapping(value="logout.do")
  114. public String logout(@ModelAttribute("user")users user, SessionStatus status){
  115. if(user != null){
  116. status.setComplete();
  117. }
  118. return "redirect:index.do";
  119. }
  120. @RequestMapping(value="myindex.do")
  121. public String myidex(){
  122. return "personal/myindex";
  123. }
  124. http://www.kmrlyy.com/fujianyan/33455.html
  125. @RequestMapping(value="mynews.do",method=RequestMethod.GET)
  126. public String preMyNews(@ModelAttribute("user")users user, ModelMap map){
  127. int userid = user.getId();
  128. newsService ns = new newsServiceImpl();
  129. List<news> lstn = ns.getNewsByUserId(userid);
  130. map.addAttribute("news", lstn);
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值