Implementation of campus mutual aid forum platform based on SSM

About the author: Java, front-end, and Python have been developed for many years, and have worked as engineers, project managers, and architects.

Main contents: Java project development, Python project development, university data and AI project development, microcontroller project design, interview technology compilation, latest technology sharing

Collect, like and don’t get lost. It’s good to follow the author.

Get the source code at the end of the article

 Project number: BS-PT-117

1. Introduction to the environment

Locale: Java: jdk1.8

Database: Mysql: mysql5.7

Application server: Tomcat: tomcat8.5.31

Development tools: IDEA or eclipse

Development technology: SSM+JSP

2. Project Introduction

This project implements a campus mutual aid forum management system platform based on the SSM framework and JSP. System users are divided into registered users and platform administrators. Registered users can register and log in online, post online, reply to posts, like, report, leave online messages, view announcements, etc. Administrators can manage user information, post categories, post information, reply information, message information, announcement information, report information, and manage the system's carousel images and friendly links. See the function display below for details.

3. System display

System homepage

You can reply to posts, report them, like them, etc.

Personal center

Backend administrator login

Backend management module

4. Core code display

package com.spring.controller;

import com.jntoo.db.*;
import com.jntoo.db.utils.*;
import com.spring.dao.*;
import com.spring.entity.*;
import com.spring.service.*;
import com.spring.util.*;
import java.util.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 管理员 模块访问入口
 */
@Controller
public class AdminsController extends BaseController {

    @Autowired
    private AdminsMapper dao;

    @Autowired
    private AdminsService service;

    /**
     *  后台列表页
     *
     */
    @RequestMapping("/admins_list")
    public String list() {
        // 检测是否有登录,没登录则跳转到登录页面
        if (!checkLogin()) {
            return showError("尚未登录", "./login.do");
        }

        String order = Request.get("order", "id"); // 获取浏览器上地址栏参数 order  如果没有则设置为id
        String sort = Request.get("sort", "desc"); // 获取浏览器上地址栏参数 sort  如果没有则设置为desc

        SelectExample example = new SelectExample(); //  创建一个搜索类
        String where = " 1=1 "; // 创建初始条件为:1=1
        where += getWhere(); // 从方法中获取url 上的参数,并写成 sql条件语句
        example.setWhere(where); // 将条件写进sql里面
        example.setOrder(order + " " + sort); // 设置查询的排序情况

        int page = request.getParameter("page") == null ? 1 : Integer.valueOf(request.getParameter("page")); // 获取前台提交的URL参数 page  如果没有则设置为1
        page = Math.max(1, page); // 取两个数的最大值,防止page 小于1
        List<Admins> list = service.selectPage(example, page, 12); // 获取当前页的行数
        // 将列表写给界面使用
        assign("list", list);
        assign("orderby", order); // 把当前排序结果写进前台
        assign("sort", sort); // 把当前排序结果写进前台
        assign("where", where); // 把当前条件写给前台
        return "admins_list"; // 使用视图文件:WebRoot\admins_list.jsp
    }

    /**
     *  获取前台搜索框填写的内容,并组成where 语句
     */
    public String getWhere() {
        String where = " ";
        // 以下是判断搜索框中是否有输入内容,判断是否前台是否有填写相关条件,符合则写入sql搜索语句
        if (!Request.get("username").equals("")) {
            where += " AND username LIKE '%" + Request.get("username") + "%' ";
        }
        return where;
    }

    @RequestMapping("/admins_add")
    public String add() {
        if (!checkLogin()) {
            return showError("尚未登录", "./");
        }
        return "admins_add";
    }

    @RequestMapping("/admins_updt")
    public String updt() {
        int id = Request.getInt("id");
        // 获取行数据,并赋值给前台jsp页面
        Admins mmm = service.find(id);
        request.setAttribute("mmm", mmm);
        request.setAttribute("updtself", 0);
        return "admins_updt";
    }

    @RequestMapping("/admins_updtself")
    public String updtself() {
        // 更新个人资料
        int id = (int) request.getSession().getAttribute("id");
        Admins mmm = service.find(id);
        request.setAttribute("mmm", mmm);
        request.setAttribute("updtself", 1);

        return "admins_updtself";
    }

    /**
     * 添加内容
     * @return
     */
    @RequestMapping("/adminsinsert")
    public String insert() {
        String tmp = "";
        Admins post = new Admins(); // 创建实体类
        // 设置前台提交上来的数据到实体类中
        post.setUsername(Request.get("username"));

        post.setPwd(Request.get("pwd"));

        service.insert(post); // 插入数据
        int charuid = post.getId().intValue();

        return showSuccess("保存成功", Request.get("referer").equals("") ? request.getHeader("referer") : Request.get("referer"));
    }

    /**
     * 更新内容
     * @return
     */
    @RequestMapping("/adminsupdate")
    public String update() {
        // 创建实体类
        Admins post = new Admins();
        // 将前台表单数据填充到实体类
        if (!Request.get("username").equals("")) post.setUsername(Request.get("username"));
        if (!Request.get("pwd").equals("")) post.setPwd(Request.get("pwd"));

        post.setId(Request.getInt("id"));
        service.update(post); // 更新数据
        int charuid = post.getId().intValue();
        if (Request.getInt("updtself") == 1) {
            return showSuccess("保存成功", "admins_updtself.do");
        }
        return showSuccess("保存成功", Request.get("referer")); // 弹出保存成功,并跳转到前台提交的 referer 页面
    }

    /**
     *  删除
     */
    @RequestMapping("/admins_delete")
    public String delete() {
        if (!checkLogin()) {
            return showError("尚未登录");
        }
        int id = Request.getInt("id"); // 根据id 删除某行数据
        Map map = Query.make("admins").find(id);

        service.delete(id); // 根据id 删除某行数据
        return showSuccess("删除成功", request.getHeader("referer")); //弹出删除成功,并跳回上一页
    }
}
package com.spring.controller;

import com.alibaba.fastjson.*;
import com.jntoo.db.*;
import com.jntoo.db.utils.*;
import com.spring.dao.*;
import com.spring.entity.*;
import com.spring.service.*;
import com.spring.util.*;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 公共路由
 */
@Controller
public class CommonController extends BaseController {

    /**
     * 使用ajax 检测某表中某个字段是否已存在,已存在则无法提交
     * @return
     */
    @RequestMapping(value = "/checkno")
    @ResponseBody
    public String checkon() {
        String table = request.getParameter("table");
        String col = request.getParameter("col");
        String checktype = request.getParameter("checktype");
        String value = request.getParameter(col);

        // 检测新添加的
        if (checktype.equals("insert")) {
            if (Query.make(table).where(col, value).count() > 0) {
                return "false";
            } else {
                return "true";
            }
            // 检测更新的
        } else if (checktype.equals("update")) {
            String id = request.getParameter("id") == null ? "" : request.getParameter("id");
            if (Query.make(table).where(col, value).where("id", "neq", id).count() > 0) {
                return "false";
            } else {
                return "true";
            }
        }
        return "false";
    }

    /**
     * 审核数据,将是否审核改为已审核状态,点击一下 是 则变否, 点击一下 否 变为是
     * @return
     */
    @RequestMapping("/sh")
    @ResponseBody
    public String sh() {
        String yuan = request.getParameter("yuan");
        String id = request.getParameter("id");
        String tablename = request.getParameter("tablename");
        String sql = "";
        if (yuan.equals("是")) {
            sql = "update " + tablename + " set issh='否' where id=" + id;
        } else {
            sql = "update " + tablename + " set issh='是' where id=" + id;
        }
        DB.execute(sql);
        return "<script>location.href='" + request.getHeader("Referer") + "';</script>";
    }

    /**
     * 通过ajax获取表的某行数据
     * @return
     */
    @RequestMapping("/tableAjax")
    @ResponseBody
    public String tableFind() {
        String table = request.getParameter("table");
        String id = request.getParameter("id");
        Map map = Query.make(table).where("id", id).find();
        //JSONObject json = JSONObject.parse(map);
        return JSON.toJSONString(map); //.toString();
    }

    /**
     * 搜索下拉某表的数据
     * @return
     */
    @RequestMapping("/selectUpdateSearch")
    @ResponseBody
    public String selectUpdateSearch() {
        String table = Request.get("table");
        Query query = Query.make(table);
        String limit = "50";
        JSONObject where = JSON.parseObject(Request.get("where"));
        for (Map.Entry entry : where.entrySet()) {
            String key = (String) entry.getKey();
            Object value = entry.getValue();
            if ("limit".equals(key)) {
                limit = String.valueOf(value);
            } else {
                if (value instanceof JSONObject) {
                    JSONObject w = (JSONObject) value;
                    query.where(key, w.getString("exp"), w.getString("value"));
                } else if (value instanceof JSONArray) {
                    JSONArray w = (JSONArray) value;
                    query.where(key, (String) w.get(0), w.get(1));
                } else {
                    query.where(key, value);
                }
            }
        }
        List list = query.order("id desc").limit(limit).select();
        return JSON.toJSONString(list);
    }
}

5. Display of related works

Practical projects based on Java development, Python development, PHP development, C# development and other related languages

Front-end practical projects developed based on Nodejs, Vue and other front-end technologies

Related works based on WeChat applet and Android APP application development

Development and application of embedded Internet of Things based on 51 microcontroller and other embedded devices

AI intelligent applications based on various algorithms

Various data management and recommendation systems based on big data

 

 

Guess you like

Origin blog.csdn.net/whirlwind526/article/details/132898226