• Java项目:校园相册管理系统(java+SSM+html+bootstrap+layui+Mysql)


    源码获取:俺的博客首页 "资源" 里下载! 

    项目介绍

    实现了用户登录与注册,查看首页,查看我的相册,添加相册,提交评论,修改密码等功能

    环境需要

    1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
    2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
    3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
    4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 
    5.数据库:MySql 5.7版本;
    6.是否Maven项目:是;


    技术栈

    1. 后端:Spring+SpringMVC+Mybatis
    2. 前端:html+CSS+JavaScript+bootstrap+layui

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;
    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;
    若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;
    3. 将项目中jdbc.properties配置文件中的数据库配置改为自己的配置;
    4. 运行项目,在浏览器中输入 http://localhost:8080/ssm_xcselect


     

     

     

     

     

    系统用户管理控制层:

    1. /**
    2. * 系统用户
    3. *
    4. */
    5. @RestController
    6. @RequestMapping("/sys/user")
    7. public class SysUserController extends AbstractController {
    8. @Autowired
    9. private SysUserService sysUserService;
    10. @Autowired
    11. private SysUserRoleService sysUserRoleService;
    12. /**
    13. * 所有用户列表
    14. */
    15. @RequestMapping("/list")
    16. @RequiresPermissions("sys:user:list")
    17. public R list(@RequestParam Map<String, Object> params) {
    18. //查询列表数据
    19. Query query = new Query(params);
    20. List<SysUserEntity> userList = sysUserService.queryList(query);
    21. int total = sysUserService.queryTotal(query);
    22. PageUtils pageUtil = new PageUtils(userList, total, query.getLimit(), query.getPage());
    23. return R.ok().put("page", pageUtil);
    24. }
    25. @RequestMapping("/list2")
    26. public R list2(@RequestParam Map<String, Object> params) {
    27. //查询列表数据
    28. Query query = new Query(params);
    29. List<SysUserEntity> userList = sysUserService.queryList(query);
    30. return R.ok().put("list", userList);
    31. }
    32. /**
    33. * 获取登录的用户信息
    34. */
    35. @RequestMapping("/info")
    36. public R info() {
    37. return R.ok().put("user", getUser());
    38. }
    39. /**
    40. * 修改登录用户密码
    41. */
    42. @SysLog("修改密码")
    43. @RequestMapping("/password")
    44. public R password(String password, String newPassword) {
    45. Assert.isBlank(newPassword, "新密码不为能空");
    46. //sha256加密
    47. password = new Sha256Hash(password).toHex();
    48. //sha256加密
    49. newPassword = new Sha256Hash(newPassword).toHex();
    50. //更新密码
    51. int count = sysUserService.updatePassword(getUserId(), password, newPassword);
    52. if (count == 0) {
    53. return R.error("原密码不正确");
    54. }
    55. //退出
    56. ShiroUtils.logout();
    57. return R.ok();
    58. }
    59. @SysLog("修改个人信息")
    60. @RequestMapping("/updateInfo")
    61. public R updateInfo(String mobile, String email) {
    62. getUser().setMobile(mobile);
    63. getUser().setEmail(email);
    64. getUser().setPassword(null);
    65. this.sysUserService.update(getUser());
    66. return R.ok();
    67. }
    68. /**
    69. * 用户信息
    70. */
    71. @RequestMapping("/info/{userId}")
    72. @RequiresPermissions("sys:user:info")
    73. public R info(@PathVariable("userId") Long userId) {
    74. SysUserEntity user = sysUserService.queryObject(userId);
    75. //获取用户所属的角色列表
    76. List<Long> roleIdList = sysUserRoleService.queryRoleIdList(userId);
    77. user.setRoleIdList(roleIdList);
    78. return R.ok().put("user", user);
    79. }
    80. /**
    81. * 保存用户
    82. */
    83. @SysLog("保存用户")
    84. @RequestMapping("/save")
    85. @RequiresPermissions("sys:user:save")
    86. public R save(@RequestBody SysUserEntity user) {
    87. ValidatorUtils.validateEntity(user, AddGroup.class);
    88. user.setCreateUserId(getUserId());
    89. sysUserService.save(user);
    90. return R.ok();
    91. }
    92. /**
    93. * 修改用户
    94. */
    95. @SysLog("修改用户")
    96. @RequestMapping("/update")
    97. @RequiresPermissions("sys:user:update")
    98. public R update(@RequestBody SysUserEntity user) {
    99. ValidatorUtils.validateEntity(user, UpdateGroup.class);
    100. user.setCreateUserId(getUserId());
    101. sysUserService.update(user);
    102. return R.ok();
    103. }
    104. /**
    105. * 删除用户
    106. */
    107. @SysLog("删除用户")
    108. @RequestMapping("/delete")
    109. @RequiresPermissions("sys:user:delete")
    110. public R delete(@RequestBody Long[] userIds) {
    111. if (ArrayUtils.contains(userIds, 1L) || ArrayUtils.contains(userIds, -1L)) {
    112. return R.error("系统管理员不能删除");
    113. }
    114. if (ArrayUtils.contains(userIds, getUserId())) {
    115. return R.error("当前用户不能删除");
    116. }
    117. sysUserService.deleteBatch(userIds);
    118. return R.ok();
    119. }
    120. }

    登录管理控制层: 

    1. /**
    2. * 登录相关
    3. *
    4. */
    5. @Controller
    6. public class SysLoginController {
    7. @Autowired
    8. private Producer producer;
    9. @Autowired
    10. private SysUserService sysUserService;
    11. @RequestMapping("captcha.jpg")
    12. public void captcha(HttpServletResponse response) throws ServletException, IOException {
    13. response.setHeader("Cache-Control", "no-store, no-cache");
    14. response.setContentType("image/jpeg");
    15. //生成文字验证码
    16. String text = producer.createText();
    17. //生成图片验证码
    18. BufferedImage image = producer.createImage(text);
    19. //保存到shiro session
    20. ShiroUtils.setSessionAttribute(Constants.KAPTCHA_SESSION_KEY, text);
    21. ServletOutputStream out = response.getOutputStream();
    22. ImageIO.write(image, "jpg", out);
    23. }
    24. /**
    25. * 登录
    26. */
    27. @ResponseBody
    28. @RequestMapping(value = "/sys/login", method = RequestMethod.POST)
    29. public R login(String username, String password, String captcha) throws IOException {
    30. // String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
    31. // if(!captcha.equalsIgnoreCase(kaptcha)){
    32. // return R.error("验证码不正确");
    33. // }
    34. try {
    35. Subject subject = ShiroUtils.getSubject();
    36. //sha256加密
    37. password = new Sha256Hash(password).toHex();
    38. UsernamePasswordToken token = new UsernamePasswordToken(username, password);
    39. subject.login(token);
    40. } catch (UnknownAccountException e) {
    41. return R.error(e.getMessage());
    42. } catch (IncorrectCredentialsException e) {
    43. return R.error(e.getMessage());
    44. } catch (LockedAccountException e) {
    45. return R.error(e.getMessage());
    46. } catch (AuthenticationException e) {
    47. return R.error("账户验证失败");
    48. }
    49. return R.ok();
    50. }
    51. /**
    52. */
    53. @ResponseBody
    54. @RequestMapping(value = "/sys/reg", method = RequestMethod.POST)
    55. public R reg(String username, String password, String captcha) throws IOException {
    56. // String kaptcha = ShiroUtils.getKaptcha(Constants.KAPTCHA_SESSION_KEY);
    57. // if(!captcha.equalsIgnoreCase(kaptcha)){
    58. // return R.error("验证码不正确");
    59. // }
    60. //sha256加密
    61. SysUserEntity user = new SysUserEntity();
    62. user.setUsername(username);
    63. user.setPassword(password);
    64. user.setStatus(1);
    65. List<Long> roles = new ArrayList<>();
    66. roles.add(1L);
    67. user.setRoleIdList(roles);
    68. this.sysUserService.save(user);
    69. return R.ok();
    70. }
    71. /**
    72. * 退出
    73. */
    74. @RequestMapping(value = "logout", method = RequestMethod.GET)
    75. public String logout() {
    76. ShiroUtils.logout();
    77. return "redirect:login.html";
    78. }
    79. }

    文件上传管理控制层:

    1. /**
    2. * 文件上传
    3. *
    4. */
    5. @RestController
    6. @RequestMapping("file")
    7. public class UploadController extends AbstractController {
    8. public static String[] suffixs = {"IMG", "PNG", "JPG", "JPEG", "GIF", "BPM"};
    9. @Autowired
    10. PicService picService;
    11. /**
    12. * 上传文件
    13. */
    14. @RequestMapping("/upload")
    15. public R upload(@RequestParam("file") MultipartFile aaa, Long id, HttpServletRequest request) throws Exception {
    16. MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
    17. for (MultipartFile f : req.getFiles("file")) {
    18. PicEntity p = new PicEntity();
    19. p.setUrl(MultipartFileUtil.uploadFile("", f, request));
    20. p.setUser(super.getUserId());
    21. p.setShare("0");
    22. p.setView(1d);
    23. p.setTitle(f.getOriginalFilename());
    24. p.setAlbum(id);
    25. this.picService.save(p);
    26. }
    27. return R.ok();
    28. }
    29. @RequestMapping("/upload1")
    30. public R upload1(@RequestParam("file") MultipartFile aaa, Long id, HttpServletRequest request) throws Exception {
    31. MultipartHttpServletRequest req = (MultipartHttpServletRequest) request;
    32. for (MultipartFile f : req.getFiles("file")) {
    33. return R.ok().put("url", MultipartFileUtil.uploadFile("", f, request));
    34. }
    35. return R.ok();
    36. }
    37. /**
    38. * 上传资讯内容的图片
    39. *
    40. * @param upload 图片
    41. * @param response 响应
    42. */
    43. @ResponseBody
    44. @RequestMapping("ckEditorUpload")
    45. public void uploadFile(MultipartFile upload, String CKEditorFuncNum, HttpServletRequest request, HttpServletResponse response) throws IOException {
    46. response.setContentType("text/html; charset=UTF-8");
    47. PrintWriter out = response.getWriter();
    48. try {
    49. String path = null;
    50. if (upload != null && !upload.isEmpty()) {
    51. String url = MultipartFileUtil.uploadFile("/cdn", upload, request);
    52. path = url;
    53. }
    54. // 返回“图像”选项卡并显示图片
    55. out.println("<script type=\"text/javascript\">");
    56. out.println("window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ",'" + path + "','')");
    57. out.println("</script>");
    58. } catch (RuntimeException e) {
    59. out.println("<script type=\"text/javascript\">");
    60. out.println("window.parent.CKEDITOR.tools.callFunction(" + CKEditorFuncNum + ",'','" + e.getMessage() + "');");
    61. out.println("</script>");
    62. }
    63. }
    64. }

    源码获取:俺的博客首页 "资源" 里下载!

  • 相关阅读:
    [附源码]SSM计算机毕业设计班级风采网站JAVA
    华为WATCH 4系列升级鸿蒙4有哪些新变化
    神经网络算法的基本原理,神经网络算法通俗解释
    CCPC Finals 2021 (A F G J L)
    行为严究深抓住消费行为,提升品牌营销
    【C基础篇】算法、数据类型、运算符与表达式、常见输入出函数
    Git学习笔记 - Git基本操作和GitHub
    分享5款2023年不容错过的宝藏软件
    cpp中的函数重载
    java 多线程()—— 死锁
  • 原文地址:https://blog.csdn.net/m0_66863468/article/details/125631701