package cn.edu.gues.controller;
import cn.edu.gues.config.MyConfig;
import cn.edu.gues.config.SaveCacheMap;
import cn.edu.gues.pojo.Comment;
import cn.edu.gues.pojo.admin.Admin;
import cn.edu.gues.pojo.bolg.Bolg;
import cn.edu.gues.pojo.bolg.TagBolg;
import cn.edu.gues.pojo.type.Type;
import cn.edu.gues.service.admin.AdminService;
import cn.edu.gues.service.home.HomeBolgService;
import cn.edu.gues.service.user.UserBolgService;
import cn.edu.gues.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
/**
* @author yangwanjun
* @version 1.0
* @description: TODO
* @date 2022/4/10 15:14
*/
@Controller
@RequestMapping("/user")
public class UserController {
// 图片保存地址
@Value("${userDate.filePath}")
private String filePath;
@Autowired
private AdminService adminService;
@Autowired
private UserBolgService userBolgService;
@Autowired
private HomeBolgService homeBolgService;
@Autowired
private SaveCacheMap userMap;
@Autowired
private UserService userService;
// 用户登录
@PostMapping("/verify")
public String loginVerify(String username, String password, HttpServletRequest request, Model model) {
Admin user = userMap.getUsername(request);
if (user != null && user.getPassword().equals(password)) {
model.addAttribute("avatar", user.getAvatar());
model.addAttribute("nickName", user.getNickName());
model.addAttribute("user", user.getUsername());
model.addAttribute("authorImage", user.getAuthorImage());
return "user/index";
}
if (username == null || username.isEmpty() || password == null || password.isEmpty()) {
model.addAttribute("message", "密码错误");
homeIndex(model);
return "home/index";
}//可以在这里加个验证,防止恶意访问
Admin user2 = userService.login(username, password);
if (user2 == null) {
model.addAttribute("message", "密码错误");
return "user/login";
} else if (user2.getType() == 1) {
model.addAttribute("message", "密码错误");
return "user/login";
} else {
model.addAttribute("avatar", user2.getAvatar());
model.addAttribute("nickName", user2.getNickName());
model.addAttribute("user", user2.getUsername());
model.addAttribute("authorImage", user2.getAuthorImage());
userMap.saveUser(user2, request);
}
return "user/index";
}
public void homeIndex(Model model) {
List<Bolg> bolgList = homeBolgService.getBolgList(1, 10);
model.addAttribute("bolgList", bolgList);
model.addAttribute("current", 1);
Integer count = homeBolgService.bolgPageSize();
model.addAttribute("bolgPageSize", count);
model.addAttribute("appreciation", homeBolgService.getAppreciation());
model.addAttribute("typeList", homeBolgService.getTypeList());
model.addAttribute("lastPage", (count % 10 == 0) ? (count / 10) : (count / 10 + 1));
}
@RequestMapping("/logout")
public String logout(HttpServletRequest request, Model model) {
userMap.remove(request);
model.addAttribute("user", null);
homeIndex(model);
return "home/index";
}
@RequestMapping({"/index", "index/**", "/"})
public String index() throws IOException {
return "user/index";
}
//主页
@RequestMapping("/bolg")
public String bolg(HttpServletRequest request, Model model) {
Admin admin = userMap.getUsername(request);
bolg(model, admin, 1, 10, 1);
return "user/bolg";
}
// 转发
@RequestMapping("/personInfo")
public String personInfo(HttpServletRequest request, Model model) {
Admin admin1 = userMap.getUsername(request);
System.out.println(admin1);
model.addAttribute("username", admin1.getUsername());
model.addAttribute("password", admin1.getPassword());
model.addAttribute("email", admin1.getEmail());
model.addAttribute("nickName", admin1.getNickName());
model.addAttribute("qq", admin1.getQq());
model.addAttribute("weChat", admin1.getWeChat());
return "user/person";
}
@RequestMapping("/personDate")
public String person(Admin admin, Model model) {
if (userService.addUser(admin)) {
model.addAttribute("msg", "更新成功");
} else {
model.addAttribute("msg", "更新失败");
}
bolg(model, admin, 1, 10, 1);
return "user/bolg";
}
public void bolg(Model model, Admin admin, Integer page, Integer size, Integer current) {
List<Bolg> bolgListPage = userBolgService.bolgListPageDate(page, size, admin.getUsername());
List<Type> typeList = userBolgService.bolgTypeListPageDate();
model.addAttribute("bolgList", bolgListPage);
model.addAttribute("typeList", typeList);
model.addAttribute("current", current);
Integer pageSize = userBolgService.getBolgPageSize(size, admin.getUsername());
Integer count = pageSize / size;
model.addAttribute("endPage", (pageSize < size || pageSize % size == 0) ? count : (count + 1));
}
@Transactional
@RequestMapping("/delete")
public String delete(Model model, Long id, HttpServletRequest request, Integer current) {
Admin admin = userMap.getUsername(request);
boolean delete = userService.delete(id, admin.getUsername());
bolg(model, admin, current, 10, current);
model.addAttribute("message", delete ? "删除成功" : "删除失败");
return "user/bolg";
}
@RequestMapping("/register")
public String register(Admin admin, String passwordTwo, MultipartFile file, Model model, HttpServletRequest request) throws IOException {
if (admin.getPassword() != null && passwordTwo.equals(admin.getPassword()) && passwordTwo.length() > 5) {
admin.setPassword(MyConfig.MD5Code(passwordTwo));
if (file != null) {
String filename = file.getOriginalFilename();
String uuid = UUID.randomUUID() + filename;
file.transferTo(new File(filePath + File.separator + uuid));
admin.setAvatar("http://110.40.186.129/home/" + uuid);
}
if (userService.addUser(admin)) {
model.addAttribute("avatar", admin.getAvatar());
model.addAttribute("nickName", admin.getNickName());
model.addAttribute("user", admin.getUsername());
model.addAttribute("authorImage", admin.getAuthorImage());
userMap.saveUser(admin, request);
return "user/index";
} else {
model.addAttribute("message", "出现严重错误");
return "user/register";
}
}
model.addAttribute("message", "密码过
没有合适的资源?快使用搜索试试~ 我知道了~
后端开发个人博客,简单而又不失美感的技术博客
共2000个文件
js:585个
html:384个
css:174个
需积分: 24 3 下载量 8 浏览量
2022-04-13
00:49:32
上传
评论
收藏 88.26MB RAR 举报
温馨提示
技术栈:SpringBoot,MyBatis-Plus,MySQL,Markdown,Thymeleaf,semantic-ui 项目介绍:一个小而美的技术博客,可以直接进行云上部署,项目支持普通用户注册和发布博客,非系统用户只能查看。适合初学者练手和搭建一个自己的博客系统。 阅览地址:http://110.40.186.129/ywj 由于本人是后端开发为主,对前端的应用掌握不够,前端ui参考Github上的一个大佬。项目下载之后,导入数据库便可直接运行
资源详情
资源评论
资源推荐
收起资源包目录
后端开发个人博客,简单而又不失美感的技术博客 (2000个子文件)
002da3a1a799094f4d54ffe53cad4b012eed69 484B
006ac73c07c6453fa174e325f677b113458244 115B
008e62fa0257bdb04768fe068ab1f2fdbad85c 275B
015e533c98c07e57088220eeacdaf9233942b7 212B
015e599cb3f4ed6e43adf2976560d571d03d79 1KB
0177042bbb0f32a4c09cf6c7a01da642cfe2dc 85B
0182ad7bad192dfee0a5eec4575069ed4044ca 46B
022c0895908f3c60605609a79f05125361946d 112KB
0256d7437b6f1175798cd03f9bc2584e159def 236B
025755f364b10cf8839da88d5321f9458a8769 554B
029b623e81813f57e0cf9a98c5603d68f79a99 1KB
02dea2312d7bf2b6de68d62df400e20198cd23 7KB
0305e7b6501fc403f86e8131af9f55fd13a20b 585B
030f2f5ae6742f2a2d048ba40ec5d714402d9e 2KB
03b6aa2c8cfd5ec463e8739ef0cf44bb693d7f 87B
04cf0f04af5a0056af7949ed6cd06288f1d085 8KB
051d991fa6dd5678d69fd394c7fb7c09c85265 228B
053245d3581f9bbf6e2ff37dcac1d20ba64ac6 2KB
05ac46c3326054c0f6cdcac851e0a06e388b54 8KB
05f0af14c005a94174e4f1daf09dfdd1c711b8 264B
05f6c2a91e0260adc97f4c586fb3327c7763d7 1KB
06860dcbdb2bd48dc9bdd2657a912a255de179 745B
06a890a2524f0d66231c926f4838fee016e854 1KB
06adb86a11a8f29f640d9e637e36dd5ee1c5c1 2KB
06f63284d30ec080e97de16446ce4be86beeae 744B
07beb146908866bc581a66a277030bb429c57d 1KB
0802102a35739ba321b4989e2621842a4bcf18 6KB
082787ba9edf1fba1ef8ea3f3b77bf777a191d 64B
082b7f4849ec037e28531024e41b567659754f 88B
084ec2882480e132da7ce7f7341a8a8f498307 207B
09c080c571b7874b31913fb9b46f06811ae112 237B
09d116756d2686ed7459a0c2b8ad1e84dda1d1 358B
09d2b9d686a64466b2b41bcad5d78a1976c759 643B
0a8fd1e039df64051ed45576b073124ed6d5b1 681B
0aac9ec75882d20fbac391299d805c57f35c54 3KB
0b00906cbbebee29652360a824d547344de74e 91B
0b2fe948d217c3b1cea75dc9b22eb39431b5ad 957B
0b685b44dc4d4d8aac820880133963e0173fa2 86B
0bab67ed6be855cd67c9e1c2ac419634c67ebb 3KB
0c3931e499cdc0f5e7c88c5e0b781ed70f5e80 812B
0c3d4240dfab15e4ff4cc359769e61320d2d4f 1KB
0c6d8f3040d3a108adceb6d1d877d50a270319 84B
0cc7696f2a18eb61779863153639c39d37b40c 3KB
0df078c34dc8cddb5d1b6937c92b3a061881b7 1KB
0e2b7bfe6fbf830dc5745010d067b3f1cca72f 116B
0eb2d5180a2c8965a1e10b1980c6153e8a9ffc 3KB
0f6e78a1457a3f21a2f477a73c6197b8f71780 212B
0f7b779b80d1878de878564c5ad40d39e801a6 88B
0f95d3978364949feeb1fc99ea4a1d1da9f9cc 86B
0fa28464f78acbe97155cbf199c439ad70f3b1 85B
1021c42bff4296c86a6c75c743878941811673 839B
10288afc512b98aafaaea457bb1bbf0d76fb02 3KB
109eb85a220ce0acb8d8605589f172cf2b1d2d 904B
10b7c05924734cbc66df6b31797615615efdb4 1KB
10e34ff524ac5707281b37f031e689f399f4f5 19KB
111353ecf20a7f6ea602dfe19818b3d82bd32d 46B
117ec22f250eb64c0e68688ca8c8c066fce2e7 948B
11d585145b1cc1b9581e914acbb32d8542b4f5 55KB
125f16028c25f3d11c253bc5f40c6476a00dd5 2KB
127c293eb56dbb26c1cc69af4b1a1cd58802ec 210B
1283aa000b5ffa17db1e414dbb1b7b54584eed 249B
12d91121c3e80ca7337f239281a2c87e81b53f 6KB
13209210a4cd883e073c3125b06c2ee734895a 218B
13b5a406b981172b0ae83d675dac369531ad49 733B
13def613e219a944b47f973641c7b0485b04bf 211B
141943fa695e1a2f74535056d56637db711783 1KB
148cdbbd8c056f8251b435b4da67aa99ca8283 2KB
14b8235bea111e132a9eec392bdd9bf2ced251 6KB
14c366fccdc85267dd4c714c4da5d1882d3f02 218B
14c3695ae6ea2e019319e7871ad7b5c53605cd 1KB
15479876a5878ff0dfb22a1f81ca89b1f94a99 3KB
154b6b3e18deb197940dc33743dd5d8aa8b2df 85B
15510903e3fa64b7cc25951aa9df7f961a9411 2KB
155894941743f68d3f6d7a15c88e13046c1139 483B
15b5e1090325ea0ab2ca59b48ed323a605c98b 1KB
162f0eebedf9c03558e77fb6ffd8da71811c9f 37KB
167a5a5465a54803139ff0667a1180f7d0de04 2KB
169e2d69a5ebeea10cdc1bbad245dfc1c38197 846B
17198af02fda2b3803e08910d6f9719caa8c7c 632B
1759bce15f3eb54aaafc0fde28f327a86d00bf 1KB
179e7a216b0f8d805a91efb7a5455fba20fd2a 451B
17a77e9d65f6752cb539b8eb981fb29c68ccf8 220B
17f069370d3a545d04d51645d9b5d0846518e2 735B
18446672cfe4fd27faf76cd7a06775ac118fe9 60B
185d30b4e890f0ab0e61b13377918f12f4d2f2 925B
18c25b786843bc6522d553d712898d3eb432af 714B
1911a8db73c4a0b87114140f4cde2d7bf40b70 938B
195581cfb3d66f239c8edbf06849ead6a32445 1KB
197bb3b95472a789c77bb3abad150f81e7523e 119B
1999f5b721ec4302379bb3d9b380ab7be8f74d 243B
19abd304ae12286fee2bc18456212c393f2ad4 2KB
19ae2d3ee19e83124c683ebc85410055920d80 217B
19f5c365126de39ce8093fb2f2e4d42c5a240b 1KB
1a2247b8d64471c0a2caf99d5f6625b8dd0d58 742B
1a745839e0fd1f898f5b864b065517502cc312 5KB
1b3d950ffac5a6d705130abcc20b7c646b381c 19KB
1b782045eeb9bef7d9f9cf26d85d1678991ac8 35KB
1bb4e2c01b5ddefd6a49ef5bffa7af22ebf467 200B
1bbea5a6338dde8895b5293d8bc125ac2fb6c4 671B
1c064652ffbe71339c0e11189785613131e38c 189B
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
闲不下来的菜鸟
- 粉丝: 5
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- (源码)基于Django和OpenCV的智能车视频处理系统.zip
- (源码)基于ESP8266的WebDAV服务器与3D打印机管理系统.zip
- (源码)基于Nio实现的Mycat 2.0数据库代理系统.zip
- (源码)基于Java的高校学生就业管理系统.zip
- (源码)基于Spring Boot框架的博客系统.zip
- (源码)基于Spring Boot框架的博客管理系统.zip
- (源码)基于ESP8266和Blynk的IR设备控制系统.zip
- (源码)基于Java和JSP的校园论坛系统.zip
- (源码)基于ROS Kinetic框架的AGV激光雷达导航与SLAM系统.zip
- (源码)基于PythonDjango框架的资产管理系统.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0