首页 > 其他分享 >基于Spring Boot的二手车交易系统的设计与实现

基于Spring Boot的二手车交易系统的设计与实现

时间:2024-09-23 17:49:50浏览次数:3  
标签:return 二手车 Spring Boot user org import com public

结尾名片获取源码

开发语言:Java

框架:SpringBoot

持久化框架:Mybatis-plus

JDK版本:JDK1.8

服务器:tomcat7\8\9

数据库:mysql 5.7以上

数据库工具:Navicat11以上

开发软件:eclipse/myeclipse/idea

Maven:Maven3.5.4

浏览器:谷歌浏览器\Edge

功能描述

如今社会上各行各业,都喜欢用自己行业的专属软件工作,互联网发展到这个时候,人们已经发现离不开了互联网。新技术的产生,往往能解决一些老技术的弊端问题。因为传统二手车交易信息管理难度大,容错率低,管理人员处理数据费工费时,所以专门为解决这个难题开发了一个二手车交易系统,可以解决许多问题。

二手车交易系统可以实现汽车管理,汽车留言管理,汽车收藏管理,汽车品牌管理,公告类型管理,论坛管理,商家管理,用户管理等功能。该系统采用了Mysql数据库,Java语言,Spring Boot框架等技术进行编程实现。

二手车交易系统可以提高二手车交易信息管理问题的解决效率,优化二手车交易信息处理流程,保证二手车交易信息数据的安全,它是一个非常可靠,非常安全的应用程序。

功能展示

图5.1 即为编码实现的商家管理界面,商家信息包括联系方式,邮箱,商家名称等信息。管理可以使用修改功能对登记有误的商家信息进行修改,可以删除需要删除的商家信息等。

 图5.2 即为编码实现的公告信息管理界面,公告信息包括公告内容,图片等信息。管理可以使用修改功能对登记有误的公告信息进行修改,可以删除需要删除的公告信息等。

 图5.3 即为编码实现的论坛管理界面,论坛信息包括帖子标题,内容,发帖时间等信息,管理员可以删除需要删除的帖子信息,可以查看帖子的回复信息,可以修改帖子等。

 图5.4 即为编码实现的汽车管理界面,汽车信息包括价格,汽车照片等信息,商家可以新增汽车信息,可以下架汽车,上架汽车以及删除需要删除的汽车信息等。

 图5.5 即为编码实现的汽车留言管理界面,汽车留言内容是用户发布的信息,而汽车的回复内容是商家的回复信息。

 图5.6 即为编码实现的论坛管理界面,商家也能通过论坛管理功能新增帖子,跟踪发布的帖子,比如随时查看帖子的评论,以及查看帖子的详情等。

 图5.7 即为编码实现的汽车信息界面,用户查看汽车信息界面右侧区域展示的系统推荐的汽车信息,用户可以通过汽车介绍的查看来了解汽车,用户可以对汽车点赞或踩,也能在汽车信息界面下方的留言区域发布汽车的留言。

 图5.8 即为编码实现的在线论坛界面,用户通过在线论坛发布帖子,查看所有的帖子内容,以及用户把自己查看帖子的个人看法通过评论帖子的功能进行发布。

图5.9 即为编码实现的公告信息界面,用户在查询框中编辑公告标题即可实现对公告信息的查询,用户可以查看公告信息界面展示的任意一条公告信息。 

 

 

 

实现代码

Controller层


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();
    }
}

Dao层


package com.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.pagination.Pagination;
import com.entity.UserEntity;

/**
 * 用户
 */
public interface UserDao extends BaseMapper<UserEntity> {
	
	List<UserEntity> selectListView(@Param("ew") Wrapper<UserEntity> wrapper);

	List<UserEntity> selectListView(Pagination page,@Param("ew") Wrapper<UserEntity> wrapper);
	
}

Server层


package com.service;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Param;

import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.IService;
import com.entity.UserEntity;
import com.utils.PageUtils;


/**
 * 系统用户
 */
public interface UserService extends IService<UserEntity> {
 	PageUtils queryPage(Map<String, Object> params);
    
   	List<UserEntity> selectListView(Wrapper<UserEntity> wrapper);
   	
   	PageUtils queryPage(Map<String, Object> params,Wrapper<UserEntity> wrapper);
	   	
}

package com.service.impl;


import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dao.UserDao;
import com.entity.UserEntity;
import com.service.UserService;
import com.utils.PageUtils;
import com.utils.Query;


/**
 * 系统用户
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserDao, UserEntity> implements UserService {

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		Page<UserEntity> page = this.selectPage(
                new Query<UserEntity>(params).getPage(),
                new EntityWrapper<UserEntity>()
        );
        return new PageUtils(page);
	}

	@Override
	public List<UserEntity> selectListView(Wrapper<UserEntity> wrapper) {
		return baseMapper.selectListView(wrapper);
	}

	@Override
	public PageUtils queryPage(Map<String, Object> params,
			Wrapper<UserEntity> wrapper) {
		 Page<UserEntity> page =new Query<UserEntity>(params).getPage();
	        page.setRecords(baseMapper.selectListView(page,wrapper));
	    	PageUtils pageUtil = new PageUtils(page);
	    	return pageUtil;
	}
}

权限验证

package com.interceptor;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;

import com.annotation.IgnoreAuth;
import com.entity.EIException;
import com.entity.TokenEntity;
import com.service.TokenService;
import com.utils.R;

/**
 * 权限(Token)验证
 */
@Component
public class AuthorizationInterceptor implements HandlerInterceptor {

    public static final String LOGIN_TOKEN_KEY = "Token";

    @Autowired
    private TokenService tokenService;
    
	@Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //支持跨域请求
        response.setHeader("Access-Control-Allow-Methods", "POST, GET, OPTIONS, DELETE");
        response.setHeader("Access-Control-Max-Age", "3600");
        response.setHeader("Access-Control-Allow-Credentials", "true");
        response.setHeader("Access-Control-Allow-Headers", "x-requested-with,request-source,Token, Origin,imgType, Content-Type, cache-control,postman-token,Cookie, Accept,authorization");
        response.setHeader("Access-Control-Allow-Origin", request.getHeader("Origin"));

        IgnoreAuth annotation;
        if (handler instanceof HandlerMethod) {
            annotation = ((HandlerMethod) handler).getMethodAnnotation(IgnoreAuth.class);
        } else {
            return true;
        }

        //从header中获取token
        String token = request.getHeader(LOGIN_TOKEN_KEY);
        
        /**
         * 不需要验证权限的方法直接放过
         */
        if(annotation!=null) {
        	return true;
        }
        
        TokenEntity tokenEntity = null;
        if(StringUtils.isNotBlank(token)) {
        	tokenEntity = tokenService.getTokenEntity(token);
        }
        
        if(tokenEntity != null) {
        	request.getSession().setAttribute("userId", tokenEntity.getUserid());
        	request.getSession().setAttribute("role", tokenEntity.getRole());
        	request.getSession().setAttribute("tableName", tokenEntity.getTablename());
        	request.getSession().setAttribute("username", tokenEntity.getUsername());
        	return true;
        }
        
		PrintWriter writer = null;
		response.setCharacterEncoding("UTF-8");
		response.setContentType("application/json; charset=utf-8");
		try {
		    writer = response.getWriter();
		    writer.print(JSONObject.toJSONString(R.error(401, "请先登录")));
		} finally {
		    if(writer != null){
		        writer.close();
		    }
		}
//				throw new EIException("请先登录", 401);
		return false;
    }
}

标签:return,二手车,Spring,Boot,user,org,import,com,public
From: https://blog.csdn.net/Steve1122/article/details/142464396

相关文章

  • 【计算机毕设-软件开发类】基于SpringBoot的食品安全管理平台
    ......
  • springboot基于Java的高校学生食堂系统(源码+vue+部署文档+前后端分离等)
    收藏关注不迷路!!......
  • [AI回答]Java中Long和long的区别,为什么在Springboot项目中一般使用Long
    Long和long的区别在Java中,Long和long是两个不同的概念,它们分别代表不同的数据类型:long:这是一个基本数据类型(primitivetype)。它用于存储64位带符号的整数。它的取值范围是-9,223,372,036,854,775,808到9,223,372,036,854,775,807。在使用long类型变量时,......
  • springmvc
    一、快速入门新建项目导入依赖在web.xml中添加前端控制器构建项目结构spring配置文件编写controller类注解解释@Controller注解继承于spring代表将类交给ioc容器,在使用时需要在spring.xml中配置包扫描@RequestMapping用于建立请求URL和处理请求方法之间的对......
  • SpringUtil获取bean
    packagecom.joysuccess.dcim.alarm.utils;importorg.springframework.beans.BeansException;importorg.springframework.context.ApplicationContext;importorg.springframework.context.ApplicationContextAware;importorg.springframework.stereotype.Component;......
  • tmpspringboot流程
    SpringApplication.run方法逻辑:1、创建ApplicationArguments对象applicationArguments->newDefaultApplicationArguments(args)|-source->newDefaultApplicationArguments$Source(args)"commandLineArgs"commandLineArgssource的类图如......
  • 基于Node.js+vue基于springboot的网上点餐系统(开题+程序+论文) 计算机毕业设计
    本系统(程序+源码+数据库+调试部署+开发环境)带文档lw万字以上,文末可获取源码系统程序文件列表开题报告内容研究背景随着互联网技术的飞速发展和智能手机的普及,人们的日常生活方式发生了深刻变化,线上服务已成为不可或缺的一部分。在餐饮行业中,传统的到店点餐模式逐渐被线上......
  • 基于Node.js+vue基于springboot的宠物医院管理(开题+程序+论文) 计算机毕业设计
    本系统(程序+源码+数据库+调试部署+开发环境)带文档lw万字以上,文末可获取源码系统程序文件列表开题报告内容研究背景随着人们生活水平的提高和宠物饲养的普及,宠物已成为许多家庭不可或缺的一员。宠物健康与福利的关注度日益上升,促使宠物医疗行业迅速发展。然而,传统的宠物医......
  • SpringBoot客户管理系统设计与优化
    2系统关键技术2.1SpringBoot框架SpringBoot是Pivotal团队的一个新框架,旨在简化新Spring应用程序的初始设置和开发。该框架使用特定的配置方法,无需开发人员定义样板配置。通过这种方式,SpringBoot旨在成为蓬勃发展的快速应用程序开发领域的领导者。SpringBoot特点:1......
  • springboot入门
    一、什么是springboot提到springboot,首先就需要向大家介绍Spring框架。Spring框架是一个广泛使用的开源Java平台,它提供了全面的基础设施支持,用于开发各种Java应用程序。Spring框架具有以下优势:方便解耦,简化开发:Spring的控制反转(IoC)容器允许开发者将对象的创建和依赖关系管......