当前位置:   article > 正文

Springboot(ssm) +Vue 在线blog博客平台 个人博客系统Java(code&LW)_ssm+springboot+vue

ssm+springboot+vue

springboot(ssm)+vue 在线blog博客 个人博客Java(code&LW)

基于springboot(ssm) + vue 的前后端分离项目,数据库采用mysql。

代码、数据库以及文档保证完整可用,可提供远程调试并指导运行服务~

如果对系统的中的某些部分感到不合适可提供修改服务,比如题目、界面、功能、框架等等...

系统中有不懂的小问题皆可向我提问,如需更深层次理解系统亦可提供讲解服务(声音还怪好听的嘞~)

学长祝你早日找到合适的代码哦~

  1. //部分代码
  2. package com.controller;
  3. import java.util.Arrays;
  4. import java.util.Calendar;
  5. import java.util.Date;
  6. import java.util.Map;
  7. import javax.servlet.http.HttpServletRequest;
  8. import org.springframework.beans.factory.annotation.Autowired;
  9. import org.springframework.stereotype.Controller;
  10. import org.springframework.web.bind.annotation.GetMapping;
  11. import org.springframework.web.bind.annotation.PathVariable;
  12. import org.springframework.web.bind.annotation.PostMapping;
  13. import org.springframework.web.bind.annotation.RequestBody;
  14. import org.springframework.web.bind.annotation.RequestMapping;
  15. import org.springframework.web.bind.annotation.RequestParam;
  16. import org.springframework.web.bind.annotation.ResponseBody;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import com.annotation.IgnoreAuth;
  19. import com.baomidou.mybatisplus.mapper.EntityWrapper;
  20. import com.entity.TokenEntity;
  21. import com.entity.UserEntity;
  22. import com.service.TokenService;
  23. import com.service.UserService;
  24. import com.utils.CommonUtil;
  25. import com.utils.MPUtil;
  26. import com.utils.PageUtils;
  27. import com.utils.R;
  28. import com.utils.ValidatorUtils;
  29. /**
  30. * 登录相关
  31. */
  32. @RequestMapping("users")
  33. @RestController
  34. public class UserController{
  35. @Autowired
  36. private UserService userService;
  37. @Autowired
  38. private TokenService tokenService;
  39. /**
  40. * 登录
  41. */
  42. @IgnoreAuth
  43. @PostMapping(value = "/login")
  44. public R login(String username, String password, String captcha, HttpServletRequest request) {
  45. UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
  46. if(user==null || !user.getPassword().equals(password)) {
  47. return R.error("账号或密码不正确");
  48. }
  49. String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
  50. return R.ok().put("token", token);
  51. }
  52. /**
  53. * 注册
  54. */
  55. @IgnoreAuth
  56. @PostMapping(value = "/register")
  57. public R register(@RequestBody UserEntity user){
  58. // ValidatorUtils.validateEntity(user);
  59. if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
  60. return R.error("用户已存在");
  61. }
  62. userService.insert(user);
  63. return R.ok();
  64. }
  65. /**
  66. * 退出
  67. */
  68. @GetMapping(value = "logout")
  69. public R logout(HttpServletRequest request) {
  70. request.getSession().invalidate();
  71. return R.ok("退出成功");
  72. }
  73. /**
  74. * 密码重置
  75. */
  76. @IgnoreAuth
  77. @RequestMapping(value = "/resetPass")
  78. public R resetPass(String username, HttpServletRequest request){
  79. UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
  80. if(user==null) {
  81. return R.error("账号不存在");
  82. }
  83. user.setPassword("123456");
  84. userService.update(user,null);
  85. return R.ok("密码已重置为:123456");
  86. }
  87. /**
  88. * 列表
  89. */
  90. @RequestMapping("/page")
  91. public R page(@RequestParam Map<String, Object> params,UserEntity user){
  92. EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
  93. PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
  94. return R.ok().put("data", page);
  95. }
  96. /**
  97. * 列表
  98. */
  99. @RequestMapping("/list")
  100. public R list( UserEntity user){
  101. EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
  102. ew.allEq(MPUtil.allEQMapPre( user, "user"));
  103. return R.ok().put("data", userService.selectListView(ew));
  104. }
  105. /**
  106. * 信息
  107. */
  108. @RequestMapping("/info/{id}")
  109. public R info(@PathVariable("id") String id){
  110. UserEntity user = userService.selectById(id);
  111. return R.ok().put("data", user);
  112. }
  113. /**
  114. * 获取用户的session用户信息
  115. */
  116. @RequestMapping("/session")
  117. public R getCurrUser(HttpServletRequest request){
  118. Long id = (Long)request.getSession().getAttribute("userId");
  119. UserEntity user = userService.selectById(id);
  120. return R.ok().put("data", user);
  121. }
  122. /**
  123. * 保存
  124. */
  125. @PostMapping("/save")
  126. public R save(@RequestBody UserEntity user){
  127. // ValidatorUtils.validateEntity(user);
  128. if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
  129. return R.error("用户已存在");
  130. }
  131. userService.insert(user);
  132. return R.ok();
  133. }
  134. /**
  135. * 修改
  136. */
  137. @RequestMapping("/update")
  138. public R update(@RequestBody UserEntity user){
  139. // ValidatorUtils.validateEntity(user);
  140. UserEntity u = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername()));
  141. if(u!=null && u.getId()!=user.getId() && u.getUsername().equals(user.getUsername())) {
  142. return R.error("用户名已存在。");
  143. }
  144. userService.updateById(user);//全部更新
  145. return R.ok();
  146. }
  147. /**
  148. * 删除
  149. */
  150. @RequestMapping("/delete")
  151. public R delete(@RequestBody Long[] ids){
  152. userService.deleteBatchIds(Arrays.asList(ids));
  153. return R.ok();
  154. }
  155. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/213180
推荐阅读
相关标签
  

闽ICP备14008679号