package com.yc.controller;
import com.yc.mapper.CommentMapper;
import com.yc.mapper.ForumMapper;
import com.yc.mapper.UserMapper;
import com.yc.pojo.Comment;
import com.yc.pojo.Forum;
import com.yc.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContext;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.swing.text.html.HTML;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Controller
public class ForumController {
@Autowired
private ForumMapper forumMapper;
@Autowired
private UserMapper userMapper;
@Autowired
private CommentMapper commentMapper;
Forum forum=new Forum();
@RequestMapping({"/"})
public String Index(Model model){
List<User> userList=userMapper.userOrder();
List<Forum> forums1=forumMapper.forumTop4();
List<Forum> forums2=forumMapper.forumHot10();
List<Forum> forums3=forumMapper.forumWeekHot10();
model.addAttribute("userList",userList);
model.addAttribute("forums1",forums1);
model.addAttribute("forums2",forums2);
model.addAttribute("forums3",forums3);
return "success";
}
@RequestMapping("/detail")
public String Detail(@RequestParam("id") int id, Model model){
forumMapper.addView(id);
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
String username = authentication.getName();
forum=forumMapper.queryForumById(id);
List<Comment> comments=commentMapper.showComment(id);
List<Forum> forums=forumMapper.forumWeekHot10();
model.addAttribute("comments",comments);
model.addAttribute("forum",forum);
model.addAttribute("forums",forums);
return "detail";
}
@RequestMapping("/addComment")
public String AddComment(int topicId,String comment,Model model){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String commentTime = sdf.format(new Date());
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
String username = authentication.getName();
User user=userMapper.QueryByUserName(username);
commentMapper.addComment(topicId,comment,user.getUid(),user.getUsername(),commentTime);
forumMapper.addCommentNum(topicId);
userMapper.updateUserComment(username);
return "redirect:/detail"+"?id="+topicId;
}
@RequestMapping("/ajax")
public String Ajax(String text,Model model){
model.addAttribute("text",text);
return "test";
}
@RequestMapping({"/toAdd","add.html"})
public String toAdd(){
return "add";
}
@RequestMapping("/add")
public String Add(@RequestParam("category") String category,@RequestParam("title") String title,
@RequestParam("content") String content,@RequestParam("experience") int experience,Model model){
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String gmtCreate = sdf.format(new Date());
SecurityContext context = SecurityContextHolder.getContext();
Authentication authentication = context.getAuthentication();
String username = authentication.getName();
User user=userMapper.QueryByUserName(username);
Forum forum=new Forum();
forum.setCategory(category);
forum.setTitle(title);
forum.setContent(content);
forum.setExperience(experience);
forum.setAuthorId(user.getUid());
forum.setAuthorName(user.getUsername());
forum.setGmtCreate(gmtCreate);
forumMapper.addForum(forum);
forum=forumMapper.queryForum(title);
model.addAttribute("category",category);
model.addAttribute("title",title);
model.addAttribute("content",content);
model.addAttribute("experience",experience);
return "redirect:/detail?id="+forum.getId();
}
@RequestMapping({"/toUpdate"})
public String toUpdate1 (@RequestParam("id") int id,Model model){
forum=forumMapper.queryForumById(id);
model.addAttribute("forum",forum);
return "update";
}
@RequestMapping("/update")
public String Update(@RequestParam("category") String category,@RequestParam("title") String title,
@RequestParam("content") String content,Model model){
model.addAttribute("category",category);
model.addAttribute("title",title);
model.addAttribute("content",content);
return "test";
}
@RequestMapping("/main")
public String Main(@RequestParam("currentPage") int currentPage,@RequestParam("category") String category,Model model){
List<Forum> forums=forumMapper.queryForumByCategory(category,currentPage*15-15,15);
int totalPage=forumMapper.getTotalPage1(category).size();
totalPage=totalPage/15+1;
List<Forum> forums2=forumMapper.forumWeekHot10();
model.addAttribute("category",category);
model.addAttribute("forums",forums);
model.addAttribute("forums2",forums2);
model.addAttribute("currentPage",currentPage);
model.addAttribute("totalPage",totalPage);
return "main";
}
@RequestMapping("/search")
public String GetMain(@RequestParam("currentPage") int currentPage,@RequestParam("search") String search,Model model){
List<Forum> forums=forumMapper.queryForumByTitle("%"+search+"%",currentPage*15-15,15);
int totalPage=forumMapper.getTotalPage("%"+search+"%").size();
totalPage=totalPage/15+1;
List<Forum> forums2=forumMapper.forumWeekHot10();
model.addAttribute("search",search);
model.addAttribute("forums",forums);
model.addAttribute("forums2",forums2);
model.addAttribute("currentPage",currentPage);
model.addAttribute("totalPage",totalPage);
return "search";
}
@RequestMapping("/del")
public String Delete(int id,Model model){
forumMapper.deleteForumById(id);
List<Forum> forums1=forumMapper.forumTop4();
List<Forum> forums2=forumMapper.forumHot10();
List<Forum> forums3=forumMapper.forumWeekHot10();
model.addAttribute("forums1",forums1);
model.addAttribute("forums2",forums2);
model.addAttribute("forums3",forums3);
return "success";
}
@RequestMapping("/top")
public void Top(){
}
@RequestMapping("/essence")
public void Essence(){
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
收起资源包目录
基于spring boot的论坛系统的源码 (1351个子文件)
01f1cdc1ea83511abdf46f99dab7b0e351dce6 3KB
0294452f84cb4ae86545af080d298240e6f318 12KB
02a6376ec4e61dbe2889ad621120c27b5c21f5 229B
038d6514c2c42ad765d66e7414477d3c65c0e5 3KB
04237751911ef84414cc2676a0f7f50548ba7c 244B
065087d4720326776b26c7b9d2482c9e467bca 2KB
068ebab0a2c36ae20ff9f6b1e86c7081476f2c 1KB
06cf9d4f67015d8379a9e50c0e6f713052f563 3KB
06dec7665103e978f47e459cd7882ba8e422a2 18KB
07c47dec950bc4eb64df0c6d2d9cbba9cf33d7 247B
09ca038846bb9f7b8ce5ef63a30ceedb5ecb3f 234B
0b700850553a3d7be8d33cf6622c5a832cb1f0 2KB
0bb28b7e71a407f47aa6f0ff92f7f1ef9e8853 100B
0bbc2a0384e5654525e7581017364dd9ceb59c 3KB
0bd8b0023c25e74fac444bfecd6c5d7a0dc448 2KB
0be3f7b9084f0258639e6077e89b3d918a1085 1KB
0c212d02f0542bba1b31724fb14ab282f5eb9d 1KB
0cdbd94007cac35ce238b066861f6ff6fd60a5 58B
0d2eacad8c51fed788794759548b9f0ccba1f3 270B
0d8bfc9a5db267bc450514995d48eca1afc828 1KB
0e750c47cf87001d726ba417131a1e20a2ced4 3KB
102df5cfc9ddc8a10c89205f5c29ef6a93cb30 3KB
105729d51dfc055af20cc5f2d90a8105094bd2 2KB
111077d1f3149455c86e0f870479f7bddb165e 593B
111a38c849fa06175a318fa98625c38d717398 2KB
115828a08b595f94c4aa302947cd50535925e0 3KB
122b857bccb7d96b8527684a95f42b2208ce6f 182B
137891791fe96927ad78e64b0aad7bded08bdc 16B
13ce0f2947465ea4586d475a0c11fb694f15fe 1KB
15f89d79ed82cdb1f53aed2378d887915528f3 3KB
160d24203925c3f0f32de1e56fd94124c3d1d2 227B
16c5fbc418e94ca578e26f729c989ae5b14048 243B
17da8b1aaae2935e19ac97d9015f0fe24e8770 11KB
17f02c1ea0ecd96651c2619505cf43abee4443 8KB
194728da9d42155e78a59460b3a8cacc6efae3 8KB
194f576f22c7f3a7896fdd3df73c6f16dcf1eb 6KB
1a18ec21f6922962eb0a727cdca2c3d123ed8e 120B
1a3486d006be1fa09c43e2826bbbef0c76cf81 69B
1a62d9f7b0141173fe01b18d4b1b97babc56ab 50B
1a8e901679ba19c7d5bde4b4bb7c91e9dce6d9 49B
1a9df8296072b182005148449411c8b7459f7b 75B
1ba79e4dd451b9fb1578ff6c3a7b0f4d90ef2b 2KB
1ba8c4b46af9bbbc658e0076aa20d23deb5fbf 181B
1c88a3e8658cde7b25b6e063d23d010f7ed86a 3KB
1d3da1620bad3ccbe0724dbbd04bf3d7f236e7 49B
1ee33a8c610c7505279bd40a0f01d284b43a16 249B
1fbeac5dde454cd0182cc1e6e329214ec73ad3 3KB
202e57765637de3bd4a7ecd6999fb8b8a8b882 66B
20674a9fe8318da0a67c3489157efe98217c39 983B
208c8503b9e668f03478caaaf1685d6b6a8a15 4KB
20a14da82d200032c79cac281c45ea464849f6 238B
213f73868a39471664c431bdb5073055eb36d5 230B
2200c51ee924f0b91132e5cd3737fadcf40ef8 3KB
223e2d01b24620b210f66c4461ab67d10efcaf 2KB
229ce3e82cb0f1ec67292e953fc9bf08bb12ba 218B
22c15191813f23654c9ebca3cf49eacf9a56c2 410B
22e7ff12a215188dfc4d0314e91cee7526e739 2KB
2395692754999bb7e7c6e434d7884a962582d5 239B
246ae1cab497ce43d8c6527e4332be42443c2b 245B
25e5bd09b4a6ca2d1d7e78c1830e9df69dac13 1KB
262bcbdf921ff1193833aa0b7245ebfac47401 669B
268c4b602fab3d6bfc801c7267e3bdb2a4094d 97B
272e3ee317b67f5d8fbff7c4937c126dd9f620 1KB
2737f71dcb50ccc11ed41aba0d40976105bd59 2KB
279c52f7c8e9e1c4f65060488990c9e3985571 7KB
28318edd48f35299f6c6f83b03057fa33665dc 7KB
287e0b3e5e20f69adfcb9a8b141acf0dd33b63 5KB
2916d4031609830f26ef77c17ad26906ac9717 2KB
2931b78986e412c13cf19b583a2b282c89b85f 678B
2af6965b2985af5a6e0e3285551be7e51ad600 249B
2bea2e3410d2d663d467f9d63cef9a8b49dc41 197B
2c9a8716753a48d1d7a72cca450aa48480d960 11KB
2caed91af025fb4360f40fab4c498f54be0471 1KB
2d572ce90e5085986bdd9c9204b9404f028084 130B
2db4ede9c41d967a70c9cabc90ccdd1266e257 235B
2dcf2158851511ebc2079a7bf0478810306a11 44B
2e4864e1cb40d3949c177ad2b762c70ab69fcb 466B
2ec63023161fe91520f9c51d2e8a31f592fc57 117B
2f0b2234a9c03bbfb9578056143ef4516bd965 2KB
303584954e7a1a793788c75b9e2526404dea0f 63B
30374cd0fb32bb78b6a39505fda263f96644ed 1KB
310efe969db76a62ef8d948ce38a8e1e7d5633 984B
31b0636bc8f30b2172b608a44a90119b29ced6 3KB
31e75fc078c189a380ad1478cd4a09d572b0d5 2KB
321c7eb0e5b5bdbdd10b93907b8eaeb3bf11bf 3KB
322643dae616390d8263e8cf1bc4d9fdfa03ec 2KB
3287c0edf110f5624af1934220b464e239e5e0 8KB
32c94ff0b234bc55ad13ad7724dc55f881e7ea 2KB
32dde991ffc008772566f1a11e57ae77fe9d9d 187B
33f7c4f762b5c4eda2a630793d681345423734 2KB
34309dd4e63472327c695b1ac5744cbad3629e 370B
34548e8780d66ccd2de35bb2475db92c7e0489 3KB
34aa0538d29343fd8acda7b2cb199efa85e78d 219B
35912d2872b24721e9805e8764ee0ce05da1c7 6KB
366c887ca15c22e37e0678a593fc084182ff00 719B
36de2d6768dbc170530570fb646efb8c0928ad 592B
37790b04175e0b50a2ba396d6d47f62fb9b534 16KB
37fcaf214a394d8efb68f5d48c9ec6f9ea1fa3 3KB
38598d2d0847fbadfb4e77408726e58508be9e 5KB
3906335612d80b6fb1c2725b4cd530fd590e05 184B
共 1351 条
- 1
- 2
- 3
- 4
- 5
- 6
- 14
资源推荐
资源预览
资源评论
5星 · 资源好评率100%
5星 · 资源好评率100%
116 浏览量
5星 · 资源好评率100%
116 浏览量
136 浏览量
2023-05-10 上传
2017-12-19 上传
5星 · 资源好评率100%
128 浏览量
5星 · 资源好评率100%
2024-03-17 上传
2019-01-29 上传
2024-01-15 上传
5星 · 资源好评率100%
5星 · 资源好评率100%
2024-12-17 上传
2024-03-05 上传
2024-01-10 上传
2023-05-23 上传
资源评论
sunshine000424
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 塑料检测23-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- Python圣诞节倒计时与节日活动管理系统
- 数据结构之哈希查找方法
- 系统DLL文件修复工具
- 塑料、玻璃、金属、纸张、木材检测36-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
- Python新年庆典倒计时与节日活动智能管理助手
- Nosql期末复习资料
- 数据结构排序算法:插入排序、希尔排序、冒泡排序及快速排序算法
- 2011-2024年各省数字普惠金融指数数据.zip
- 计算机程序设计员三级(选择题)
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功