👉文末查看项目功能视频演示+获取源码+sql脚本+视频导入教程视频
1 、功能描述
基于SSM的二手交易管理系统1拥有两种角色
- 管理员:商品管理、订单管理、充值管理、用户管理等
- 用户:发布商品、查看闲置、充值账户、查看所有订单、发布求购信息、修改个人信息、关注列表等
1.1 背景描述
二手交易管理系统是一个基于SSM(Spring + SpringMVC + MyBatis)的Web应用程序,旨在提供一个方便、高效的平台,用于管理二手商品交易。该系统包括用户管理、商品管理、订单管理、支付管理等功能。
系统采用Spring框架作为整体架构,通过SpringMVC模块进行请求处理和数据传递,使用MyBatis作为持久层框架,实现数据的持久化。系统还采用了MySQL数据库进行数据存储,并使用Tomcat服务器进行部署。
用户管理模块负责管理用户信息,包括用户注册、登录、找回密码等功能。商品管理模块负责管理二手商品信息,包括商品的添加、修改、删除等功能。订单管理模块负责管理订单信息,包括订单的生成、支付、发货等功能。支付管理模块负责管理支付信息,包括支付方式的添加、修改、删除等功能。
该系统具有友好的用户界面和灵活的功能设计,可满足不同用户的需求。通过该系统,用户可以更加方便地进行二手商品交易,提高交易的效率和安全性。
2、项目技术
后端框架:SSM(Spring、SpringMVC、Mybatis)
前端技术:Bootstrap、jsp、css、JavaScript、JQuery
2.1 SSM
SSM(Spring+SpringMVC+MyBatis)是目前比较主流的Java EE企业级框架,适用于搭建各种大型的企业级应用系统。其中,Spring就像是整个项目中的粘合剂,负责装配bean并管理其生命周期,实现控制反转(IoC)的功能。SpringMVC负责拦截用户请求,通过DispatcherServlet将请求匹配到相应的Controller并执行。而MyBatis则是对JDBC的封装,让数据库底层操作变得透明,通过配置文件关联到各实体类的Mapper文件,实现了SQL语句映射。
2.2 mysql
MySQL是一款Relational Database Management System,直译过来的意思就是关系型数据库管理系统,MySQL有着它独特的特点,这些特点使他成为目前最流行的RDBMS之一,MySQL想比与其他数据库如ORACLE、DB2等,它属于一款体积小、速度快的数据库,重点是它符合本次毕业设计的真实租赁环境,拥有成本低,开发源码这些特点,这也是选择它的主要原因。
3、开发环境
- JAVA版本:JDK1.8
- IDE类型:IDEA、Eclipse都可运行
- tomcat版本:Tomcat 7-10版本均可
- 数据库类型:MySql(5.x和8.x版本都可)
- maven项目:否
- 硬件环境:Windows 或者 Mac OS
4、功能截图+视频演示+文档目录
4.1 登录
4.2 前端模块
4.3 用户模块
4.4 管理员模块
4.4 文档目录
5 、核心代码实现
5.1 配置代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<!-- 加载数据库参数 -->
<context:property-placeholder location="classpath:conf/jdbc.properties"/>
<context:component-scan base-package="com.ldu.service.impl"/>
<bean id = "dataSource" class = "com.alibaba.druid.pool.DruidDataSource" destroy-method = "close">
<!-- 数据库基本信息配置 -->
<property name = "url" value = "${druid.url}" />
<property name = "username" value = "${druid.username}" />
<property name = "password" value = "${druid.password}" />
<property name = "driverClassName" value = "${druid.driverClassName}" />
<property name = "filters" value = "${druid.filters}" />
<!-- 最大并发连接数 -->
<property name = "maxActive" value = "${druid.maxActive}" />
<!-- 初始化连接数量 -->
<property name = "initialSize" value = "${druid.initialSize}" />
<!-- 配置获取连接等待超时的时间 -->
<property name = "maxWait" value = "${druid.maxWait}" />
<!-- 最小空闲连接数 -->
<property name = "minIdle" value = "${druid.minIdle}" />
<!-- 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒 -->
<property name = "timeBetweenEvictionRunsMillis" value ="${druid.timeBetweenEvictionRunsMillis}" />
<!-- 配置一个连接在池中最小生存的时间,单位是毫秒 -->
<property name = "minEvictableIdleTimeMillis" value ="${druid.minEvictableIdleTimeMillis}" />
<property name = "validationQuery" value = "${druid.validationQuery}" />
<property name = "testWhileIdle" value = "${druid.testWhileIdle}" />
<property name = "testOnBorrow" value = "${druid.testOnBorrow}" />
<property name = "testOnReturn" value = "${druid.testOnReturn}" />
<property name = "maxOpenPreparedStatements" value ="${druid.maxOpenPreparedStatements}" />
<!-- 打开 removeAbandoned 功能 -->
<property name = "removeAbandoned" value = "${druid.removeAbandoned}" />
<!-- 1800 秒,也就是 30 分钟 -->
<property name = "removeAbandonedTimeout" value ="${druid.removeAbandonedTimeout}" />
<!-- 关闭 abanded 连接时输出错误日志 -->
<property name = "logAbandoned" value = "${druid.logAbandoned}" />
</bean>
<!-- 配置MyBatis的sqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
<property name="configLocation" value="classpath:conf/mybatis-config.xml"></property>
<property name="mapperLocations" value="classpath:mapper/*.xml"></property>
</bean>
<!-- Mapper接口所在包名,Spring会自动查找其下的Mapper -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="com.ldu.dao"></property>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
</bean>
<!-- 配置transactionManager事务管理器 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<!-- 配置事物通知属性 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<!-- 定义事物传播特性 -->
<tx:attributes>
<tx:method name="insert" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED" />
<tx:method name="edit*" propagation="REQUIRED" />
<tx:method name="save*" propagation="REQUIRED" />
<tx:method name="add*" propagation="REQUIRED" />
<tx:method name="new*" propagation="REQUIRED" />
<tx:method name="set*" propagation="REQUIRED" />
<tx:method name="remove*" propagation="REQUIRED" />
<tx:method name="delete*" propagation="REQUIRED" />
<tx:method name="change*" propagation="REQUIRED" />
<tx:method name="check*" propagation="REQUIRED" />
<tx:method name="get*" propagation="REQUIRED" read-only="true" />
<tx:method name="find*" propagation="REQUIRED" read-only="true" />
<tx:method name="load*" propagation="REQUIRED" read-only="true" />
<tx:method name="*" propagation="REQUIRED" read-only="true" />
</tx:attributes>
</tx:advice>
<!-- 配置事物切面 -->
<aop:config>
<aop:pointcut expression="execution(* com.ldu.service.*.*(..))" id="serviceOperation"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>
</aop:config>
</beans>
5.2 用户核心代码
package com.ldu.controller;
import com.ldu.pojo.Focus;
import com.ldu.pojo.Goods;
import com.ldu.pojo.GoodsExtend;
import com.ldu.pojo.Image;
import com.ldu.pojo.Notice;
import com.ldu.pojo.NoticeExtend;
import com.ldu.pojo.Purse;
import com.ldu.pojo.User;
import com.ldu.service.FocusService;
import com.ldu.service.GoodsService;
import com.ldu.service.ImageService;
import com.ldu.service.NoticeService;
import com.ldu.service.PurseService;
import com.ldu.service.UserService;
import com.ldu.util.DateUtil;
import com.ldu.util.MD5;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@Controller
@RequestMapping(value = "/user")
public class UserController {
@Resource
private UserService userService;
@Resource
private GoodsService goodsService;
@Resource
private ImageService imageService;
@Resource
private FocusService focusService;
@Resource
private PurseService purseService;
@Resource
private NoticeService noticeService;
/**
* 用户注册
*
* @param user1
* @return
*/
@RequestMapping(value = "/addUser")
public String addUser(HttpServletRequest request, @ModelAttribute("user") User user1) {
String url = request.getHeader("Referer");
User user = userService.getUserByPhone(user1.getPhone());
if (user == null) {// 检测该用户是否已经注册
String t = DateUtil.getNowDate();
// 对密码进行MD5加密
String str = MD5.md5(user1.getPassword());
user1.setCreateAt(t);// 创建开始时间
user1.setPassword(str);
user1.setGoodsNum(0);
user1.setStatus((byte) 1);//初始正常状态
user1.setPower(100);
userService.addUser(user1);
purseService.addPurse(user1.getId());// 注册的时候同时生成钱包
}
return "redirect:" + url;
}
/**
* 注册验证账号
* @param request
* @return
*/
@RequestMapping(value = "/register",method = RequestMethod.POST)
@ResponseBody
public String register(HttpServletRequest request){
String phone=request.getParameter("phone");
User user = userService.getUserByPhone(phone);
if(user==null) {
return "{\"success\":true,\"flag\":false}";//用户存在,注册失败
}else {
return "{\"success\":true,\"flag\":true}";//用户不存在,可以注册
}
}
/**
* 登陆验证密码
* @param request
* @return
*/
/*@RequestMapping(value = "/password",method = RequestMethod.POST)
@ResponseBody
public String password(HttpServletRequest request){
String phone=request.getParameter("phone");
String password=request.getParameter("password");
if((phone==null||phone=="")&&(password==null||password=="")) {
return "{\"success\":false,\"flag\":true}";
}else {
User user = userService.getUserByPhone(phone);
if(user==null) {
return "{\"success\":false,\"flag\":false}";//账号错误
}
String pwd = MD5.md5(password);
if (pwd.equals(user.getPassword())) {
return "{\"success\":true,\"flag\":false}";//密码正确
}else {
return "{\"success\":true,\"flag\":true}";//密码错误
}
}
}*/
/**
* 验证登录
* @param request
* @param user
* @param modelMap
* @return
*/
@RequestMapping(value = "/login")
public ModelAndView loginValidate(HttpServletRequest request, HttpServletResponse response, User user,
ModelMap modelMap) {
User cur_user = userService.getUserByPhone(user.getPhone());
String url = request.getHeader("Referer");
if (cur_user != null) {
String pwd = MD5.md5(user.getPassword());
if (pwd.equals(cur_user.getPassword())) {
if(cur_user.getStatus()==1) {
request.getSession().setAttribute("cur_user", cur_user);
return new ModelAndView("redirect:" + url);
}
}
}
return new ModelAndView("redirect:" + url);
}
/**
* 更改用户名
*
* @param request
* @param user
* @param modelMap
* @return
*/
@RequestMapping(value = "/changeName")
public ModelAndView changeName(HttpServletRequest request, User user, ModelMap modelMap) {
String url = request.getHeader("Referer");
// 从session中获取出当前用户
User cur_user = (User) request.getSession().getAttribute("cur_user");
cur_user.setUsername(user.getUsername());// 更改当前用户的用户名
userService.updateUserName(cur_user);// 执行修改操作
request.getSession().setAttribute("cur_user", cur_user);// 修改session值
return new ModelAndView("redirect:" + url);
}
/**
* 完善或修改信息
*
* @param request
* @param user
* @param modelMap
* @return
*/
@RequestMapping(value = "/updateInfo")
public ModelAndView updateInfo(HttpServletRequest request, User user, ModelMap modelMap) {
// 从session中获取出当前用户
User cur_user = (User) request.getSession().getAttribute("cur_user");
cur_user.setUsername(user.getUsername());
cur_user.setQq(user.getQq());
userService.updateUserName(cur_user);// 执行修改操作
request.getSession().setAttribute("cur_user", cur_user);// 修改session值
return new ModelAndView("redirect:/user/basic");
}
/**
* 用户退出
*
* @param request
* @return
*/
@RequestMapping(value = "/logout")
public String logout(HttpServletRequest request) {
request.getSession().setAttribute("cur_user", null);
return "redirect:/goods/homeGoods";
}
/**
* 个人中心
*
* @return
*/
@RequestMapping(value = "/home")
public ModelAndView home(HttpServletRequest request) {
ModelAndView mv = new ModelAndView();
User cur_user = (User) request.getSession().getAttribute("cur_user");
Integer userId = cur_user.getId();
int size=5;
Purse myPurse = purseService.getPurseByUserId(userId);
List<User> users=userService.getUserOrderByDate(size);
List<Notice> notice=noticeService.getNoticeList();
mv.addObject("notice", notice);
mv.addObject("myPurse", myPurse);
mv.addObject("users", users);
mv.setViewName("/user/home");
return mv;
}
/**
* 个人信息设置
*
* @return
*/
@RequestMapping(value = "/basic")
public ModelAndView basic(HttpServletRequest request) {
User cur_user = (User) request.getSession().getAttribute("cur_user");
Integer userId = cur_user.getId();
Purse myPurse = purseService.getPurseByUserId(userId);
ModelAndView mv = new ModelAndView();
mv.addObject("myPurse", myPurse);
mv.setViewName("/user/basic");
return mv;
}
/**
* 我的闲置 查询出所有的用户商品以及商品对应的图片
*
* @return 返回的model为 goodsAndImage对象,该对象中包含goods 和 images,参考相应的类
*/
@RequestMapping(value = "/allGoods")
public ModelAndView goods(HttpServletRequest request) {
User cur_user = (User) request.getSession().getAttribute("cur_user");
Integer userId = cur_user.getId();
List<Goods> goodsList = goodsService.getGoodsByUserId(userId);
List<GoodsExtend> goodsAndImage = new ArrayList<GoodsExtend>();
for (int i = 0; i < goodsList.size(); i++) {
// 将用户信息和image信息封装到GoodsExtend类中,传给前台
GoodsExtend goodsExtend = new GoodsExtend();
Goods goods = goodsList.get(i);
List<Image> images = imageService.getImagesByGoodsPrimaryKey(goods.getId());
goodsExtend.setGoods(goods);
goodsExtend.setImages(images);
goodsAndImage.add(i, goodsExtend);
}
Purse myPurse = purseService.getPurseByUserId(userId);
ModelAndView mv = new ModelAndView();
mv.addObject("goodsAndImage", goodsAndImage);
mv.setViewName("/user/goods");
mv.addObject("myPurse", myPurse);
return mv;
}
/**
* 我的关注 查询出所有的用户商品以及商品对应的图片
*
* @return 返回的model为 goodsAndImage对象,该对象中包含goods 和 images,参考相应的类
*/
@RequestMapping(value = "/allFocus")
public ModelAndView focus(HttpServletRequest request) {
User cur_user = (User) request.getSession().getAttribute("cur_user");
Integer userId = cur_user.getId();
List<Focus> focusList = focusService.getFocusByUserId(userId);
List<GoodsExtend> goodsAndImage = new ArrayList<GoodsExtend>();
for (int i = 0; i < focusList.size(); i++) {
// 将用户信息和image信息封装到GoodsExtend类中,传给前台
GoodsExtend goodsExtend = new GoodsExtend();
Focus focus = focusList.get(i);
Goods goods = goodsService.getGoodsByPrimaryKey(focus.getGoodsId());
List<Image> images = imageService.getImagesByGoodsPrimaryKey(focus.getGoodsId());
goodsExtend.setGoods(goods);
goodsExtend.setImages(images);
goodsAndImage.add(i, goodsExtend);
}
Purse myPurse = purseService.getPurseByUserId(userId);
ModelAndView mv = new ModelAndView();
mv.addObject("goodsAndImage", goodsAndImage);
mv.addObject("myPurse", myPurse);
mv.setViewName("/user/focus");
return mv;
}
/**
* 删除我的关注
* @return
*/
@RequestMapping(value = "/deleteFocus/{id}")
public String deleteFocus(HttpServletRequest request, @PathVariable("id") Integer goods_id) {
User cur_user = (User) request.getSession().getAttribute("cur_user");
Integer user_id = cur_user.getId();
focusService.deleteFocusByUserIdAndGoodsId(goods_id, user_id);
return "redirect:/user/allFocus";
}
/**
* 添加我的关注
*
* @return
*/
@RequestMapping(value = "/addFocus/{id}")
public String addFocus(HttpServletRequest request, @PathVariable("id") Integer goods_id) {
User cur_user = (User) request.getSession().getAttribute("cur_user");
Integer user_id = cur_user.getId();
//首先获取用户所有的关注列表
List<Focus> focus=focusService.getFocusByUserId(user_id);
//若关注列表为空,则直接添加关注
if(focus.isEmpty()) {
focusService.addFocusByUserIdAndId(goods_id, user_id);
return "redirect:/user/allFocus";
}
//遍历所有的关注列表
for (Focus myfocus : focus) {
int goodsId=myfocus.getGoodsId();
//若该商品已经被关注,则直接返回
if(goodsId == goods_id.intValue()) {
return "redirect:/user/allFocus";
}
}
focusService.addFocusByUserIdAndId(goods_id, user_id);
return "redirect:/user/allFocus";
}
/**
* 我的钱包
*
* @return 返回的model为 goodsAndImage对象
*/
@RequestMapping(value = "/myPurse")
public ModelAndView getMoney(HttpServletRequest request) {
User cur_user = (User) request.getSession().getAttribute("cur_user");
Integer user_id = cur_user.getId();
Purse purse = purseService.getPurseByUserId(user_id);
ModelAndView mv = new ModelAndView();
mv.addObject("myPurse", purse);
mv.setViewName("/user/purse");
return mv;
}
/**
* 充值与提现 根据传过来的两个值进行判断是充值还是提现
*
* @return 返回的model为 goodsAndImage对象
*/
@RequestMapping(value = "/updatePurse")
public String updatePurse(HttpServletRequest request, Purse purse) {
User cur_user = (User) request.getSession().getAttribute("cur_user");
Integer user_id = cur_user.getId();
purse.setUserId(user_id);
purse.setState(0);
if (purse.getRecharge() != null) {
purseService.updatePurse(purse);
}
if (purse.getWithdrawals() != null) {
purseService.updatePurse(purse);
}
return "redirect:/user/myPurse";
}
@RequestMapping(value = "/insertSelective",method = RequestMethod.POST)
@ResponseBody
public String insertSelective(HttpServletRequest request){
String context=request.getParameter("context");
User cur_user = (User) request.getSession().getAttribute("cur_user");
Notice notice=new Notice();
notice.setContext(context);
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
notice.setCreateAt(sdf.format(dt));
notice.setStatus((byte) 0);
notice.setUser(cur_user);
if(context==null||context=="") {
return "{\"success\":false,\"msg\":\"发布失败,请输入内容!\"}";
}
try {
noticeService.insertSelective(notice);
} catch (Exception e) {
return "{\"success\":false,\"msg\":\"发布失败!\"}";
}
return "{\"success\":true,\"msg\":\"发布成功!\"}";
}
}
6 、功能视频演示
基于SSM的二手物品交易系统