毕设项目 基于SSM与LayUI的校内信息共享平台


0 项目说明

基于SSM与LayUI的校内信息共享平台

提示:适合用于课程设计或毕业设计,工作量达标,源码开放


1 项目简介

这是一个类似于论坛的信息发布平台,后端基于SpringBoot开发,前端使用LayUI框架 + freemarker动态模板生成,数据库使用MySQL
MVC三层架构

2 开发环境

  • 操作系统:Windows 10
  • 构建工具:Apache Maven
  • 集成开发工具:Intellij IDEA
  • 应用服务器:Apache Tomcat
  • 接口测试工具:Postman
  • 压力测试工具:Apache JMeter
  • 版本控制工具:Git
  • Java 版本:8

3 界面展示

  • 登录页

在这里插入图片描述

  • 文章详情

在这里插入图片描述

  • 发表文章

在这里插入图片描述

4 项目源码

package com.zbin.cisp.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zbin.cisp.domain.User;
import com.zbin.cisp.service.UserService;
import com.zbin.cisp.utils.FileUtil;
import com.zbin.cisp.utils.PasswordUtil;
import com.zbin.cisp.utils.ReturnJson;
import java.util.HashMap;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

/**
 * Created by Zbin on 2019-02-14
 */
@Controller
public class UserController {

  @Resource
  UserService userService;

  @PostMapping("/doRegister")
  @ResponseBody
  public ReturnJson doRegister(@RequestBody User user) {
    try {
      if (userService.isUsernameExsit(user.getUsername())) {
        return new ReturnJson(2, "用户已存在!", 0, "");
      }
      if ("男".equals(user.getGender())) {
        user.setAvatar("http://cdn.iwzb.top/5ccc8bb0-497a-47d7-b02a-d5de38b212d6.png");
      }
      if ("女".equals(user.getGender())) {
        user.setAvatar("http://cdn.iwzb.top/2f1e6296-b266-468d-a8f8-eaa2c4ddd65a.png");
      }
      userService.register(user);
      return new ReturnJson(0, "注册成功", 0, "");
    } catch (Exception e) {
      return new ReturnJson(1, "发生了一些错误", 0, "");
    }
  }

  @PostMapping("/doLogin")
  @ResponseBody
  public ReturnJson doLogin(HttpServletRequest request, @RequestBody User user) {
    User newUser = userService.loginCheck(user);
    if (newUser != null) {
      request.getSession().setAttribute("user", newUser);
      if ("管理员".equals(newUser.getType())) {
        request.getSession().setAttribute("adminUser", newUser);
      }
      request.getSession().setMaxInactiveInterval(1800);
      return new ReturnJson(0, "登录成功", 0, "");
    } else {
      return new ReturnJson(1, "用户名或密码错误", 0, "");
    }
  }

  @PostMapping("/adminLogin")
  @ResponseBody
  public ReturnJson adminLogin(HttpServletRequest request, @RequestBody User user) {
    try {
      User adminUser = userService.getUserByUsername(user.getUsername());
      if (adminUser == null) {
        return new ReturnJson(1, "用户不存在!", 0, "");
      }
      if (!PasswordUtil.validPwd(user.getPassword(), adminUser.getPassword())) {
        return new ReturnJson(1, "用户名或密码错误", 0, "");
      }
      if (!"管理员".equals(adminUser.getType())) {
        return new ReturnJson(1, "该用户不是管理员!", 0, "");
      }
      request.getSession().setAttribute("adminUser", adminUser);
      return new ReturnJson(0, "登录成功");
    } catch (Exception e) {
      return new ReturnJson(1, "登录失败");
    }
  }

  @RequestMapping("/logout")
  public void logout(HttpServletRequest request, HttpServletResponse response) throws Exception {
    request.getSession().invalidate();
    response.sendRedirect("/index");
  }

  @PostMapping("/user/update")
  @ResponseBody
  public ReturnJson userUpdate(HttpServletRequest request, @RequestBody User user) {
    try {
      userService.updateUser(user);
      request.getSession().setAttribute("user", userService.getUserByUsername(user.getUsername()));
      return new ReturnJson("修改成功");
    } catch (Exception e) {
      return new ReturnJson("修改失败");
    }
  }

  @PostMapping("/user/setAvatar")
  @ResponseBody
  public ReturnJson userSetAvatar(HttpServletRequest request, MultipartFile file) {
    try {
      String imgUrl = FileUtil.upload(file);
      User user = (User) request.getSession().getAttribute("user");
      user.setAvatar(imgUrl);
      userService.updateUser(user);
      request.getSession().setAttribute("user", userService.getUserByUsername(user.getUsername()));
      Map<String, String> imgMap = new HashMap<>();
      imgMap.put("src", imgUrl);
      imgMap.put("title", file.getOriginalFilename());
      return new ReturnJson("设置成功", imgMap);
    } catch (Exception e) {
      return new ReturnJson("上传失败");
    }

  }

  @PostMapping("/user/changePwd")
  @ResponseBody
  public ReturnJson userChangePwd(HttpServletRequest request, @RequestBody String param) {
    try {
      JSONObject json = JSON.parseObject(param);
      String oldPwd = json.getString("oldPwd");
      String newPwd = json.getString("newPwd");
      User user = (User) request.getSession().getAttribute("user");
      user.setPassword(oldPwd);
      user = userService.loginCheck(user);
      if (user == null) {
        return new ReturnJson(1, "密码不正确");
      } else {
        user.setPassword(PasswordUtil.bryptPwd(newPwd));
        userService.updateUser(user);
        return new ReturnJson(0, "修改成功");
      }
    } catch (Exception e) {
      return new ReturnJson("修改失败");
    }
  }

  @PostMapping("/user/changeStatus")
  @ResponseBody
  public ReturnJson userChangeStatus(HttpServletRequest request, @RequestBody String param) {
    try {
      JSONObject json = JSON.parseObject(param);
      String username = json.getString("username");
      String status = json.getString("status");
      User user = new User();
      user.setUsername(username);
      user.setStatus(status);
      userService.updateUser(user);
      return new ReturnJson(0, "修改状态成功");
    } catch (Exception e) {
      return new ReturnJson("修改状态失败");
    }
  }

  @PostMapping("/user/delete")
  @ResponseBody
  public ReturnJson userDelete(HttpServletRequest request, @RequestBody String param) {
    try {
      JSONObject json = JSON.parseObject(param);
      Integer id = json.getInteger("id");
      userService.deleteById(id);
      return new ReturnJson(0, "删除成功");
    } catch (Exception e) {
      return new ReturnJson("删除失败");
    }
  }
}

5 最后

**项目分享: ** https://gitee.com/asoonis/htw

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值