基于SSM的校园旧书交易交换平台

news2025/2/22 1:52:31

末尾获取源码
开发语言:Java
Java开发工具:JDK1.8
后端框架:SSM
前端:采用JSP技术开发
数据库:MySQL5.7和Navicat管理工具结合
服务器:Tomcat8.5
开发软件:IDEA / Eclipse
是否Maven项目:是


目录

一、项目简介

二、系统功能

三、系统项目截图

3.1前台首页

3.2后台管理

四、核心代码

4.1登录相关

4.2文件上传

4.3封装


一、项目简介

本文介绍一款基于SSM(Spring+SpringMVC+MyBatis)框架的校园旧书交易交换平台,该平台功能齐全,分为管理员、发布人和学生三个角色,满足各类用户的需求。管理员可以进行密码修改、个人信息修改、学生管理、发布人管理、书籍分类管理、书籍信息管理、交易信息管理、交换信息管理、系统管理等操作;发布人可以进行书籍信息管理、交易信息管理、交换信息管理等操作;学生可以查看书籍信息并且可以申请交换、查看校园公告等功能。

本平台提供简便快捷的校园旧书交易交换服务,能够帮助校园内的学生们解决旧书处理的难题,让他们在闲置的书籍中找到自己需要的,并通过交换方式完成交易。同时,该平台也鼓励学生们回收利用旧书,达到环保的目的。

本平台采用前后端分离的开发方式,前端使用Bootstrap框架进行开发,具有响应式设计,在PC端和移动端均能良好地展现。后端使用Spring+SpringMVC+MyBatis框架,实现了作为平台核心的交换功能。数据库采用MySQL,实现数据的存储和管理。同时,引入了验证码、登录拦截器等技术,增加了系统的安全性。

本文的贡献在于提供了一种方便校园内旧书交易和交换的解决方案,同时也为学生们提供了一个更加便捷的交流平台。通过平台的运作,不仅能够让学生们方便地获取需要的书籍,同时也能够促进校园内的书籍回收利用,有利于实现校园环保。本文还对技术的运用进行详细介绍,提供了一种SSM框架在实现Web应用中的应用实例。


二、系统功能

基于SSM的校园旧书交易交换平台有以下三种角色:

(1)管理员模块:修改密码、个人信息修改、学生管理、发布人管理、书籍分类管理、书籍信息管理、交易信息管理、交换信息管理、系统管理等功能;

(2)发布人:书籍信息管理、交易信息管理、交换信息管理等功能;

(3)学生用户:有查看书籍信息并且可以申请交换、查看校园公告等功能;



三、系统项目截图

3.1前台首页

系统前台学生登录页面。

 登录后的学生可以在个人中心查看自己的信息并且可以进行修改。

 在书籍信息中可以选择自己喜欢的书籍信息与发布人进行交易。

 书籍信息详情页面显示,喜欢可以选择进行交易。

 选择好自己要交易的书籍提交后发布人会审核。

 校园公告显示。

3.2后台管理

后台登录页面显示。 

学生管理页面显示。

发布人管理页面显示。

 书籍分类管理页面显示。

书籍信息管理页面显示。

书籍交易信息页面显示。

 校园公告发布页面显示。


四、核心代码

4.1登录相关


package com.controller;


import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.TokenEntity;
import com.entity.UserEntity;
import com.service.TokenService;
import com.service.UserService;
import com.utils.CommonUtil;
import com.utils.MD5Util;
import com.utils.MPUtil;
import com.utils.PageUtils;
import com.utils.R;
import com.utils.ValidatorUtils;

/**
 * 登录相关
 */
@RequestMapping("users")
@RestController
public class UserController{
	
	@Autowired
	private UserService userService;
	
	@Autowired
	private TokenService tokenService;

	/**
	 * 登录
	 */
	@IgnoreAuth
	@PostMapping(value = "/login")
	public R login(String username, String password, String captcha, HttpServletRequest request) {
		UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
		if(user==null || !user.getPassword().equals(password)) {
			return R.error("账号或密码不正确");
		}
		String token = tokenService.generateToken(user.getId(),username, "users", user.getRole());
		return R.ok().put("token", token);
	}
	
	/**
	 * 注册
	 */
	@IgnoreAuth
	@PostMapping(value = "/register")
	public R register(@RequestBody UserEntity user){
//    	ValidatorUtils.validateEntity(user);
    	if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
    		return R.error("用户已存在");
    	}
        userService.insert(user);
        return R.ok();
    }

	/**
	 * 退出
	 */
	@GetMapping(value = "logout")
	public R logout(HttpServletRequest request) {
		request.getSession().invalidate();
		return R.ok("退出成功");
	}
	
	/**
     * 密码重置
     */
    @IgnoreAuth
	@RequestMapping(value = "/resetPass")
    public R resetPass(String username, HttpServletRequest request){
    	UserEntity user = userService.selectOne(new EntityWrapper<UserEntity>().eq("username", username));
    	if(user==null) {
    		return R.error("账号不存在");
    	}
    	user.setPassword("123456");
        userService.update(user,null);
        return R.ok("密码已重置为:123456");
    }
	
	/**
     * 列表
     */
    @RequestMapping("/page")
    public R page(@RequestParam Map<String, Object> params,UserEntity user){
        EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
    	PageUtils page = userService.queryPage(params, MPUtil.sort(MPUtil.between(MPUtil.allLike(ew, user), params), params));
        return R.ok().put("data", page);
    }

	/**
     * 列表
     */
    @RequestMapping("/list")
    public R list( UserEntity user){
       	EntityWrapper<UserEntity> ew = new EntityWrapper<UserEntity>();
      	ew.allEq(MPUtil.allEQMapPre( user, "user")); 
        return R.ok().put("data", userService.selectListView(ew));
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id){
        UserEntity user = userService.selectById(id);
        return R.ok().put("data", user);
    }
    
    /**
     * 获取用户的session用户信息
     */
    @RequestMapping("/session")
    public R getCurrUser(HttpServletRequest request){
    	Long id = (Long)request.getSession().getAttribute("userId");
        UserEntity user = userService.selectById(id);
        return R.ok().put("data", user);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    public R save(@RequestBody UserEntity user){
//    	ValidatorUtils.validateEntity(user);
    	if(userService.selectOne(new EntityWrapper<UserEntity>().eq("username", user.getUsername())) !=null) {
    		return R.error("用户已存在");
    	}
        userService.insert(user);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
//        ValidatorUtils.validateEntity(user);
        userService.updateById(user);//全部更新
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
        userService.deleteBatchIds(Arrays.asList(ids));
        return R.ok();
    }
}

4.2文件上传

package com.controller;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.annotation.IgnoreAuth;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.entity.ConfigEntity;
import com.entity.EIException;
import com.service.ConfigService;
import com.utils.R;

/**
 * 上传文件映射表
 */
@RestController
@RequestMapping("file")
@SuppressWarnings({"unchecked","rawtypes"})
public class FileController{
	@Autowired
    private ConfigService configService;
	/**
	 * 上传文件
	 */
	@RequestMapping("/upload")
	public R upload(@RequestParam("file") MultipartFile file,String type) throws Exception {
		if (file.isEmpty()) {
			throw new EIException("上传文件不能为空");
		}
		String fileExt = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")+1);
		File path = new File(ResourceUtils.getURL("classpath:static").getPath());
		if(!path.exists()) {
		    path = new File("");
		}
		File upload = new File(path.getAbsolutePath(),"/upload/");
		if(!upload.exists()) {
		    upload.mkdirs();
		}
		String fileName = new Date().getTime()+"."+fileExt;
		File dest = new File(upload.getAbsolutePath()+"/"+fileName);
		file.transferTo(dest);
		FileUtils.copyFile(dest, new File("C:\\Users\\Desktop\\jiadian\\springbootl7own\\src\\main\\resources\\static\\upload"+"/"+fileName));
		if(StringUtils.isNotBlank(type) && type.equals("1")) {
			ConfigEntity configEntity = configService.selectOne(new EntityWrapper<ConfigEntity>().eq("name", "faceFile"));
			if(configEntity==null) {
				configEntity = new ConfigEntity();
				configEntity.setName("faceFile");
				configEntity.setValue(fileName);
			} else {
				configEntity.setValue(fileName);
			}
			configService.insertOrUpdate(configEntity);
		}
		return R.ok().put("file", fileName);
	}
	
	/**
	 * 下载文件
	 */
	@IgnoreAuth
	@RequestMapping("/download")
	public ResponseEntity<byte[]> download(@RequestParam String fileName) {
		try {
			File path = new File(ResourceUtils.getURL("classpath:static").getPath());
			if(!path.exists()) {
			    path = new File("");
			}
			File upload = new File(path.getAbsolutePath(),"/upload/");
			if(!upload.exists()) {
			    upload.mkdirs();
			}
			File file = new File(upload.getAbsolutePath()+"/"+fileName);
			if(file.exists()){
				/*if(!fileService.canRead(file, SessionManager.getSessionUser())){
					getResponse().sendError(403);
				}*/
				HttpHeaders headers = new HttpHeaders();
			    headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);    
			    headers.setContentDispositionFormData("attachment", fileName);    
			    return new ResponseEntity<byte[]>(FileUtils.readFileToByteArray(file),headers, HttpStatus.CREATED);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		return new ResponseEntity<byte[]>(HttpStatus.INTERNAL_SERVER_ERROR);
	}
	
}

4.3封装

package com.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 */
public class R extends HashMap<String, Object> {
	private static final long serialVersionUID = 1L;
	
	public R() {
		put("code", 0);
	}
	
	public static R error() {
		return error(500, "未知异常,请联系管理员");
	}
	
	public static R error(String msg) {
		return error(500, msg);
	}
	
	public static R error(int code, String msg) {
		R r = new R();
		r.put("code", code);
		r.put("msg", msg);
		return r;
	}

	public static R ok(String msg) {
		R r = new R();
		r.put("msg", msg);
		return r;
	}
	
	public static R ok(Map<String, Object> map) {
		R r = new R();
		r.putAll(map);
		return r;
	}
	
	public static R ok() {
		return new R();
	}

	public R put(String key, Object value) {
		super.put(key, value);
		return this;
	}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/602841.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Mybatis_plus——标准分页功能制作

mybatispuls中提供分页查询中需要两个参数&#xff0c;一个是IPage接口的实现类&#xff0c;还有一个后面说。 IPage有且只有一个实现类Page类型在里面已经提供有了&#xff0c;传两个参数即可使用&#xff0c;一个是页码值&#xff0c;一个是每页显示数据的条数。查询完之后可…

chatgpt赋能python:Python代做:让您的网站更友好的SEO利器

Python代做&#xff1a;让您的网站更友好的SEO利器 如果您是一位网站管理员或者SEO工程师&#xff0c;您一定知道SEO对于网站的重要性。那么在SEO中&#xff0c;Python代做可以为您提供什么&#xff1f;在本文中&#xff0c;我们将通过介绍Python代做的技术和方法&#xff0c;…

unity发布webGL后无法预览解决

众所周知&#xff0c;unity发布成webgl后是无法直接预览的。因为一般来说浏览器默认都是禁止webgl运行的。 直接说我最后的解决方法&#xff1a;去vscode里下载一个live server ,安装好。 下载vscode地址Visual Studio Code - Code Editing. Redefined 期间试过几种方法都不管…

Ansys Zemax | 探究 OpticStudio 偏振分析功能

本文介绍了 OpticStudio 模拟基于偏振的光学现象的几种方法。本文的目的是在对基于偏振的光学进行建模时检查这些特征的优势和正确应用。讨论的功能包括偏振光瞳图、琼斯矩阵、双折射、表面涂层等。这些对于波片和隔离器等实际应用很重要。&#xff08;联系我们获取文章附件&am…

plt.loglog()函数的用法和示例(含代码)

目录 常用坐标下的图像显示在loglog函数下的显示同时显示参考文献 plt.loglog()函数通常是用于和对数函数相关的显示中。 在研究plt.loglog()函数之前&#xff0c;我们可以先从常见的线性平面坐标系入手。 如 np.linespace()函数,它在指定的间隔内返回均等的数字。 np.linespa…

Redis主从架构、数据同步原理、全量同步、增量同步

目录 专栏导读一、Redis主从架构二、数据同步原理三、全量同步的流程三、可以从以下几个方面来优化Redis主从就集群四、全量同步和增量同步区别&#xff1f;五、什么时候执行全量同步&#xff1f;六、什么时候执行增量同步&#xff1f;七、超卖问题 大家好&#xff0c;我是哪吒…

高完整性系统工程(八):Hoare Logic

目录 1. 霍尔逻辑&#xff08;Proving Programs Correct&#xff09; 1.1 警告&#xff08;Caveats&#xff09; 1.2 误解&#xff08;Misconception&#xff09; 1.3 编程语言&#xff08;Programming Language&#xff09; 1.4 程序&#xff08;Programs&#xff09; 1…

java学习 spring mybatis maven juc并发 缓存 分布式

Spring系列第11篇&#xff1a;bean中的autowire-candidate又是干什么的&#xff1f;_路人甲Java的博客-CSDN博客 Spring系列 Spring系列第1篇&#xff1a;为何要学spring&#xff1f; Spring系列第2篇&#xff1a;控制反转&#xff08;IoC&#xff09;与依赖注入&#xff08;DI…

I.MX RT1170加密启动详解(1):加密Boot镜像组成

使用RT1170芯片构建的所有平台一般都是高端场合&#xff0c;我们需要考虑软件的安全需求。该芯片集成了一系列安全功能。这些特性中的大多数提供针对特定类型攻击的保护&#xff0c;并且可以根据所需的保护程度配置为不同的级别。这些特性可以协同工作&#xff0c;也可以独立工…

macOS Ventura 13.5beta2 OpenCore 双引导分区原版黑苹果镜像

镜像特点&#xff08;本文原地址&#xff1a;http://www.imacosx.cn/113805.html&#xff0c;转载请注明出处&#xff09; 完全由黑果魏叔官方制作&#xff0c;针对各种机型进行默认配置&#xff0c;让黑苹果安装不再困难。系统镜像设置为双引导分区&#xff0c;全面去除clove…

【cfeng work】什么是云原生 Cloud Native

WorkProj 内容管理 云原生云原生应用十二要素应用cfeng的work理解 本文introduce 云原生 Cloud Native相关内容 随着技术的迭代&#xff0c;从最初的物理机—> 虚拟机&#xff0c;从单机 —> 分布式微服务&#xff0c; 现在的热门概念就是云☁&#xff08;cloud&#xff…

Windows 11 绕过 TPM 方法总结,通用免 TPM 镜像下载 (2023 年 5 月更新)

Windows 11 绕过 TPM 方法总结&#xff0c;通用免 TPM 镜像下载 (2023 年 5 月更新) 在虚拟机、Mac 电脑和 TPM 不符合要求的旧电脑上安装 Windows 11 的通用方法总结 请访问原文链接&#xff1a;https://sysin.org/blog/windows-11-no-tpm/&#xff0c;查看最新版。原创作品…

Tomcat安全配置

1.删除webapps里面自带文件&#xff08;关闭manage页面等&#xff09; 删除webapps目录中的docs、examples、host-manager、manager等正式环境用不着的目录&#xff0c;这一步就可以解决大部分漏洞。有的网站没删除manager页面&#xff0c;并且管理员弱口令&#xff0c;导致直…

PCL点云处理之三维凸包点提取与凸包模型生成,分别保存到PCD与PLY文件(一百七十一)

PCL点云处理之三维凸包点提取与凸包模型生成,分别保存到PCD与PLY文件(一百七十一) 一、算法介绍二、算法实现1.代码2.结果总结一、算法介绍 现给定一块点云,需要实现下面两个功能开发 (1)获取点云的三维凸包点,保存至PCD格式的文件中 (2)获取点云的三维凸包模型,保存…

华为OD机试真题B卷 Java 实现【报数游戏】,附详细解题思路

一、题目描述 100个人围成一圈&#xff0c;每个人有一个编码&#xff0c;编号从1开始到100。他们从1开始依次报数&#xff0c;报到为M的人自动退出圈圈&#xff0c;然后下一个人接着从1开始报数&#xff0c;直到剩余的人数小于M。请问最后剩余的人在原先的编号为多少&#xff…

Netty核心源码剖析(一)

准备工作 将Netty的源码包netty-all-4.1.20.Final-sources.jar添加到项目中; 在io.netty.example包下,有很多Netty源码案例,可以用来分析! 1.Netty启动过程源码剖析 1>.将io.netty.exampler.echo包下的文件复制到当前项目的其他目录中; 2>.EchoServer.java /*** Ec…

建立第一个react页面

<body><!-- 准备一个容器 --><div id"test"></div><!-- 必须在周边库之前引入核心库 --><script type"text/javascript"src"./js/react.development.js"></script><!-- 引入周边库 --><scr…

实战项目!上位机与PLC通讯

大家好&#xff0c;我是华山自控编程朱老师&#xff0c;今天给大家介绍下我之前设计的入门项目——工件正反面识别及角度测试系统 系统功能 首先&#xff0c;系统的功能包括识别工件正反面&#xff0c;测试工件旋转角度。这些任务是由PLC来控制工件传送、启动拍照以及上位机。…

张小飞的Java之路——第四十三章——字符流

写在前面&#xff1a; 视频是什么东西&#xff0c;有看文档精彩吗&#xff1f; 视频是什么东西&#xff0c;有看文档速度快吗&#xff1f; 视频是什么东西&#xff0c;有看文档效率高吗&#xff1f; 诸小亮&#xff1a;接下来我们学习——字符流 张小飞&#xff1a;刚才的…

第二十三篇、基于Arduino uno,控制RGB灯亮灭——结果导向

0、结果 说明&#xff1a;RGB灯亮红色&#xff0c;一秒钟闪烁一次&#xff0c;可以很方便的更改灯的颜色&#xff0c;如果是你想要的&#xff0c;可以接着往下看。 1、外观 说明&#xff1a;RGB灯有共阴极的&#xff0c;也有共阳极的&#xff0c;从外观上是看不出来的&#…