随着信息技术的快速发展和网络技术的日益完善,人们越来越重视电子商务。校园
二手物品交易系统是校园电子商务的一个典型代表。二手市场从以前的路边旧货市场转
变到网络中,通过二手交易系统实现了二手交易。而校园二手物品交易系统带给学生省
时、省力、省钱的货物交易平台,它使得同学们充分利用信息技术的优势去处理二手物
品,变得更加轻松、快捷、方便,能满足在校师生快速的学习和生活方式。
由于大学的扩招和当今人民生活水平的急剧提高,当代大学生的人数越来越多,规
模越来越大。当人民的生活水平提高之后,难免就会出现很多过剩物品或者丢弃很多使
用过的物品或者商品。如今这样的二手物品品种越来越丰富,可以说是琳琅满目,品种
齐全,应有尽有。在学校,二手物品的主要消费群体是学生和老师。对于学生和老师来
说,所需的主要是商品或者物品,比如说珍贵的书籍,体育设施设备、耗材,电子产品,
学习文具等。对于二手商品的使用不仅节约了消费者的购买成本,还实现了商品的二次
利用,也就是资源的再利用,这正是向我们提倡的低碳生活靠近。
如今,在校园二手交易市场上,与传统的相比,售卖方式更加地多元化,表现形式
更加新颖。比如说,第一种,在学校的宣传栏、广告栏、报刊栏,贴一些售卖物品的小
广告;第二种,通过学校后勤的批准,可以在毕业前的一段时间内,在学校制定的地方
摆放及售卖商品;第三种,就是学校会定期的举办一些购物活动,一些公司的商品会进
入学校售卖,比如移动手机、电脑耗材。这些方式会在一定的程度上满足购买者和消费
者的需求。可是,计划赶不上变化,而且生活节奏的快速变化,对于要毕业的同学来说,
忙于办理各种繁冗的毕业手续或者完成很多所选学分的课程,无闲暇时间去摆设地摊或
者向低年级的师弟师妹们售卖各种商品,毕业之后,往往他们会直接将不要的物品扔掉,
从而这些二手商品就没有得到合理的有效的使用,造成了资源浪费。而且由于大量的遗
弃之物,很有可能造成学校环境的破环,甚至有可能造成大面积的环境污染。对于毕业
生来说,生活物品无法全部带离学校,因缺乏完善的交易体系,很多物品只能被简单地
丢弃;而对新生,常常需要大量购买生活用品。这种重复行为每年都会发生,对资源造
成极大的浪费。因此,急需建立合理有效的校园二手物品循环系统,既满足学生日常对
廉价二手物品的需求,客观上提高学生的生活质量;又可以在毕业时节,高效处理原本
会被丢弃却仍具价值的旧物,减少资源浪费;同时还能在新生人学时将这些旧物出售,
减少重复购买,减少资源无意义消耗。就此,校园二手商品网站迅速出现了,并且很快
引起了同学和老师的关注。另外一方面,互联网络正处于炙热阶段,同学们及其老师的
生活开始越来越依赖计算机,据不完全统计,平均每天人至少在网上冲浪,浏览新闻等,
时间上至少两小时。因此,如果能够把校园二手交易平台移至网络,依靠网络的高效方
便的特点,将会实现更快,更好的回收利用二手物品。同时,充分利用大学生高素质高
素养的特质,能够高效的高效率的促进网站的开发及其实施。当今社会的主流正在从制
造产品转变为提供服务,关注流程的服务设计已经开始 引领设计行业的发展。该选题
旨在创建校园二手物品循环系统,希望寻找一种能够提高学生使用效率、减少负面情绪、
节约时间与物质成本的合理有序的服务。高校每年的新生人学与毕业生离校,必定产生
强制性的物品更新换代。
平台演示视频:
【java毕业设计】基于ssm jsp二手书交易系统
package com.ncu.controller;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.hamcrest.core.IsNull;
import org.springframework.beans.factory.annotation.Autowired;
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.ncu.common.RegularExpressionUtil;
import com.ncu.common.StringUtil;
import com.ncu.pojo.User;
import com.ncu.service.UserService;
@Controller
@RequestMapping("/user")
public class UserController {
@Autowired
UserService userService;
//进入登录注册页面
@RequestMapping("/index")
public ModelAndView index()throws Exception{
ModelAndView modelAndview=new ModelAndView();
modelAndview.setViewName("index");
return modelAndview;
}
//登录失败跳转页面
@RequestMapping("/loginFail")
public ModelAndView loginFail()throws Exception{
ModelAndView modelAndview=new ModelAndView();
modelAndview.setViewName("index");
modelAndview.addObject("failureInfo","用户名或密码错误!");
return modelAndview;
}
//登录
@RequestMapping("/login")
public String login(@RequestParam String user_account,@RequestParam String pwd,HttpServletRequest request)throws Exception{
User user = userService.loginValidate(user_account, pwd);
if(user!=null){
request.getSession().setAttribute("user", user);
return "redirect:/goods/showMainGoods.action";
}else{
return "redirect:/user/loginFail.action";
}
}
//退出登录
@RequestMapping("/loginout")
public String loginout(HttpServletRequest request)throws Exception{
//注销session
request.getSession().invalidate();
System.out.println("退出登录");
return "redirect:/user/index.action";
}
//注册
@RequestMapping("/register")
@ResponseBody
public Map<String, String> register(HttpServletRequest request)throws Exception{
Map<String, String> resMap=new HashMap<String, String>();
//注册信息是否合法
if(IsIegalToRegisterInfo(request,resMap)){
int res=userService.register(request);
if(res==1){
resMap.put("res", "success");
}else if(res==2){
resMap.put("res", "fail");
resMap.put("failInfo", "学号已被注册");
}else if(res==3){
resMap.put("res", "fail");
resMap.put("failInfo", "用户名已被使用");
}else if(res==4){
resMap.put("res", "fail");
resMap.put("failInfo", "手机号已被注册 ");
}else if(res==5){
resMap.put("res", "fail");
resMap.put("failInfo", "学校不存在此学号");
}
}else{
resMap.put("res", "fail");
}
return resMap;
}
//完善个人资料-界面
@RequestMapping("/user")
public ModelAndView userInfoView(HttpServletRequest request)throws Exception{
ModelAndView modelAndview=new ModelAndView();
modelAndview.setViewName("user");
return modelAndview;
}
//完善个人资料-修改个人信息功能
@RequestMapping("/updateUserInfo")
@ResponseBody
public Map<String, String> updateUserInfo(HttpServletRequest request)throws Exception{
Map<String, String> resMap=new HashMap<String, String>();
if (IsIegalToUpdateUserInfo(request, resMap)) {
boolean res =userService.updateUserInfo(request.getParameter("realName"),request.getParameter("sex"),request.getParameter("email"), ((User)request.getSession().getAttribute("user")).getId());
if(res){
resMap.put("updateRes", "success");
User user=userService.findUserById(getUserID(request));
request.getSession().setAttribute("user", user);
}else{
resMap.put("updateRes", "fail");
}
}else{
resMap.put("updateRes", "ilegal");
}
return resMap;
}
//完善个人资料-修改交易信息功能
@RequestMapping("/updateTradeInfo")
@ResponseBody
public Map<String, String> updateTradeInfo(HttpServletRequest request)throws Exception{
Map<String, String> resMap=new HashMap<String, String>();
if (IsIegalToUpdateTradeInfo(request, resMap)) {
boolean res = userService.updateTradeInfo(request.getParameter("alipayNumber"), request.getParameter("shippingAddress"),((User) request.getSession().getAttribute("user")).getId());
if (res) {
resMap.put("updateRes", "success");
User user=userService.findUserById(getUserID(request));
request.getSession().setAttribute("user", user);
} else {
resMap.put("updateRes", "fail");
}
}else{
resMap.put("updateRes", "ilegal");
}
return resMap;
}
//完善个人资料-修改密码功能
@RequestMapping("/updatePWD")
@ResponseBody
public Map<String, String> updatePWD(HttpServletRequest request)throws Exception{
Map<String, String> resMap=new HashMap<String, String>();
if (IsIegalToUpdatePWDInfo(request, resMap)) {
boolean res = userService.updatePWD(((User)request.getSession().getAttribute("user")).getPwd(),request.getParameter("pwd_old"), request.getParameter("pwd_new"),((User)request.getSession().getAttribute("user")).getId());
if(res){
resMap.put("updateRes", "success");
}else{
resMap.put("updateRes", "fail");
}
}else{
resMap.put("updateRes", "ilegal");
}
request.getSession().invalidate();
System.out.println("退出登录");
return resMap;
}
@RequestMapping("/updateHeadImg")
public ModelAndView updateHeadImg(MultipartFile headImgFile,HttpServletRequest request)throws Exception{
ModelAndView modelAndview=new ModelAndView();
modelAndview.setViewName("user");
HttpSession session = request.getSession();
User user = (User) session.getAttribute("user");
// 图片路径
String store_path = "/Data/upfilesForBS/user/headImg/";
//上传图片
String name = UUID.randomUUID().toString();
String newFileName = name + ".jpg";
File newFile = new File(request.getSession().getServletContext().getRealPath("/images"), newFileName);
newFile.getParentFile().mkdirs();
headImgFile.transferTo(newFile);
String img_name = userService.saveHeadImg("../images/"+newFileName,request.getParameter("id"));
user.setHeadImg(img_name);
return modelAndview;
}
private boolean IsIegalToUpdateUserInfo(HttpServletRequest request,Map<String, String> resMap) {
if(!RegularExpressionUtil.isUserRealName(StringUtil.messyCodetoChineseStr(request.getParameter("sex")))){
resMap.put("failInfo", "请填写真实姓名");
return false;
}
if(!RegularExpressionUtil.isUserSex(StringUtil.messyCodetoChineseStr(request.getParameter("sex")))){
resMap.put("failInfo", "性别为空或不规范");
return false;
}
if(!RegularExpressionUtil.isUserEmail(StringUtil.messyCodetoChineseStr(request.getParameter("email")))){
resMap.put("failInfo", "电子邮件不规范");
return false;
}
return true;
}
private boolean IsIegalToUpdateTradeInfo(HttpServletRequest request,Map<String, String> resMap) {
if(!RegularExpressionUtil.isUserAlipayNumber(StringUtil.messyCodetoChineseStr(request.getParameter("alipayNumber")))){
resMap.put("failInfo", "支付宝账户为空或不规范");
return false;
}
if(!RegularExpressionUtil.isUserShippingAddress(StringUtil.messyCodetoChineseStr(request.getParameter("shippingAddress")))){
resMap.put("failInfo", "收件地址为空或不规范");
return false;
}
return true;
}
private boolean IsIegalToUpdatePWDInfo(HttpServletRequest request,Map<String, String> resMap) {
if(!RegularExpressionUtil.isUserPwd(request.getParameter("pwd_old"))){
resMap.put("failInfo", "密码应大于6位小于16位字符");
return false;
}
if(!RegularExpressionUtil.isUserPwd(request.getParameter("pwd_new"))){
resMap.put("failInfo", "密码应大于6位小于16位字符");
return false;
}
return true;
}
private boolean IsIegalToRegisterInfo(HttpServletRequest request,Map<String, String> resMap) {
if(!RegularExpressionUtil.isUserSno(request.getParameter("sno"))){
resMap.put("failInfo", "学号不规范");
return false;
}
if(!RegularExpressionUtil.isUserAliasName(StringUtil.messyCodetoChineseStr(request.getParameter("aliasname")))){
resMap.put("failInfo", "用户名不能超过15个字符");
return false;
}
if(!RegularExpressionUtil.isUserPwd(request.getParameter("pwd"))){
resMap.put("failInfo", "密码应大于6位小于16位字符");
return false;
}
if(!RegularExpressionUtil.isUserMobileNumber(request.getParameter("phone_number"))){
resMap.put("failInfo", "手机号格式不规范");
return false;
}
return true;
}
private Integer getUserID(HttpServletRequest request) {
User user = (User) request.getSession().getAttribute("user");
if (user != null) {
return user.getId();
}
return null;
}
}
package com.ncu.controller;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
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.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;
import com.ncu.common.FileSaveUtils;
import com.ncu.pojo.Goods;
import com.ncu.pojo.PageBean;
import com.ncu.pojo.User;
import com.ncu.pojo.vo.CategoryVO;
import com.ncu.pojo.vo.GoodsVO;
import com.ncu.pojo.vo.MessageVO;
import com.ncu.pojo.vo.SignVO;
import com.ncu.service.CategoryService;
import com.ncu.service.GoodsService;
import com.ncu.service.MessageService;
@Controller
@RequestMapping("/goods")
public class GoodsController {
@Autowired
GoodsService goodsService;
@Autowired
MessageService messageService;
@Autowired
CategoryService categoryService;
// 首页展示10条最新发布通过书籍
@RequestMapping("/showMainGoods")
public ModelAndView showGoodsByPage(HttpServletRequest request) {
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("main");
Integer temp=null;
PageBean<Goods> pageBeanForGoods = goodsService.getGoodsByPage(1, temp);
if(pageBeanForGoods.getList().size()<=10){
modelAndView.addObject("goodsList", pageBeanForGoods.getList());
return modelAndView;
}
List<Goods> goodsList = pageBeanForGoods.getList().subList(0, 10);
modelAndView.addObject("goodsList", goodsList);
return modelAndView;
}
// 分页展示书籍
@RequestMapping("/showGoodsByPage")
public ModelAndView showGoodsByPage(HttpServletRequest request,
Integer categoryId) {
ModelAndView modelAndView = new ModelAndView();
int currentPage;
if (request.getParameter("currentPage") != null)
currentPage = Integer.parseInt(request.getParameter("currentPage"));
else
currentPage = 1;
PageBean<Goods> pageBeanForGoods = goodsService.getGoodsByPage(
currentPage, categoryId);
System.out.println(pageBeanForGoods.toString());
modelAndView.addObject("pageBeanForGoods", pageBeanForGoods);
modelAndView.setViewName("goods");
List<CategoryVO> categoryVOs = categoryService
.findAllCategoryDataWithIntroduce();
modelAndView.addObject("categoryVOs", categoryVOs);
return modelAndView;
}
// 模糊查询展示书籍
@RequestMapping("/showLikeGoodsByPage")
public ModelAndView showLikeGoodsByPage(HttpServletRequest request,String likeStr) {
ModelAndView modelAndView = new ModelAndView();
int currentPage;
if (request.getParameter("currentPage") != null)
currentPage = Integer.parseInt(request.getParameter("currentPage"));
else
currentPage = 1;
PageBean<Goods> pageBeanForGoods = goodsService.getGoodsByPage(
currentPage, likeStr);
System.out.println(pageBeanForGoods.toString());
modelAndView.addObject("pageBeanForGoods", pageBeanForGoods);
modelAndView.setViewName("goods");
List<CategoryVO> categoryVOs = categoryService
.findAllCategoryDataWithIntroduce();
modelAndView.addObject("categoryVOs", categoryVOs);
return modelAndView;
}
// 查詢自身收藏书籍
@RequestMapping("/showCollection")
public ModelAndView showGoodsForUser(Integer userId) {
ModelAndView modelAndView = new ModelAndView();
// 展示用戶收藏书籍
List<SignVO> signGoodsList = goodsService
.listGoodsForCollection(userId);
modelAndView.addObject("signGoodsList", signGoodsList);
modelAndView.setViewName("userSign");
return modelAndView;
}
// 查詢自身书籍
@RequestMapping("/showOwnerGoods")
public ModelAndView showGoodsForUser(Integer userId, Integer auditState) {
ModelAndView modelAndView = new ModelAndView();
List<GoodsVO> goodsList = goodsService.listGoodsForUser(userId,
auditState);
modelAndView.addObject("ownGoodsList", goodsList);
modelAndView.addObject("statusType", auditState);
modelAndView.setViewName("userGoods");
return modelAndView;
}
// 书籍詳細信息
@RequestMapping("/detailOfGoods")
public ModelAndView detailOfGoods(Goods goods) {
ModelAndView modelAndView = new ModelAndView();
goods = goodsService.getDetailOfGoods(goods.getId());
modelAndView.addObject("goods", goods);
String replaceAll = goods.getPicturePath().replace("/", "\\");
String path = FileSaveUtils.getSavePath() + replaceAll;
System.out.println(path);
File f = new File(path);
if (f.exists()) {
String[] fileNames = f.list(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
return !name.startsWith("thumbnail");// 返回缩略图的名字
}
});
modelAndView.addObject("files", fileNames);
}
List<MessageVO> messagesVO = messageService.findMessageOfGoods(goods
.getId());
modelAndView.addObject("messagesVO", messagesVO);
modelAndView.setViewName("detailOfGoods");
return modelAndView;
}
//查询此书籍的卖家 评论
@RequestMapping("/findOtherGoodsByCropId")
@ResponseBody
public List<Goods> findOtherGoodsByCropId(Integer cropId,Integer excludeGoodsId) throws Exception {
List<Goods> goodsList =null;
if(cropId != null){
goodsList = goodsService.findOtherGoodsOfUser(cropId, excludeGoodsId);
}
return goodsList;
}
@RequestMapping("/addGoodsView")
public ModelAndView addGoods(Goods goods, HttpServletRequest request) {
ModelAndView modelAndView = new ModelAndView();
List<CategoryVO> categories = categoryService
.findAllCategoryDataWithIntroduce();
modelAndView.setViewName("userAddGoods");
modelAndView.addObject("categories", categories);
return modelAndView;
}
// 添加书籍
@RequestMapping("/saveGoods")
public String saveGoods(Goods goods, Integer categoryId,
HttpServletRequest request, @RequestParam MultipartFile pics) throws Exception{
//上传图片
String name = UUID.randomUUID().toString();
String newFileName = name + ".jpg";
File newFile = new File(request.getSession().getServletContext().getRealPath("/images"), newFileName);
newFile.getParentFile().mkdirs();
pics.transferTo(newFile);
// String path = null;
//
// try {
// path = FileSaveUtils.getSavePath();
// String random = UUID.randomUUID().toString();
// path = path + getUserID(request) + "\\" + random + "\\";
// savePics(pics, path);
// goods.setCoverPic(1 + FileSaveUtils.getSuffixName(pics[0]));
// goods.setPicturePath(getUserID(request) + "/" + random);
// } catch (IllegalStateException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// }
goods.setPicturePath("../images/"+newFileName);
System.out.println(goods.toString() + "categoryId:" + categoryId);
boolean saveRes = goodsService.saveGoods(goods, getUserID(request),
categoryId);
if (!saveRes) {
/* modelAndView.addObject("failInfo","书籍上架異常!"); */
}
return "redirect:/goods/showOwnerGoods.action?auditState=0&userId="
+ getUserID(request);
}
// 修改书籍
@RequestMapping("/updateGoods")
public ModelAndView updateGoods(Goods goods) {
ModelAndView modelAndView = new ModelAndView();
boolean updateRes = goodsService.updateGoods(goods);
if (!updateRes) {
modelAndView.addObject("failInfo", "书籍修改異常!");
}
modelAndView.setViewName("user");
return modelAndView;
}
// 删除书籍
@RequestMapping("/removeGoods")
@ResponseBody
public Map<String, String> removeGoods(Goods goods,
HttpServletRequest request) {
Map<String, String> resMap = new HashMap<String, String>();
boolean removeRes = goodsService.removeGoods(goods.getId());
if (!removeRes) {
resMap.put("res", "fail");
}
resMap.put("res", "success");
return resMap;
}
// 查询此卖家 的其他书籍
@RequestMapping("/queryOtherGoods")
@ResponseBody
public List<Goods> queryOtherGoods(Integer userId, Integer excludeGoodsId)
throws Exception {
List<Goods> goodsList = null;
goodsList = goodsService.findOtherGoodsOfUser(userId, excludeGoodsId);
return goodsList;
}
// 审核书籍(管理员)
@RequestMapping("/auditGoods")
public ModelAndView auditGoods(Goods goods) {
ModelAndView modelAndView = new ModelAndView();
return modelAndView;
}
// 保存图片
private void savePics(MultipartFile[] pics, String path)
throws IllegalStateException, IOException {
int i = 1;
for (MultipartFile pic : pics) {
File saveFile = FileSaveUtils.saveFile(pic, path, i + "");
// 保存缩略图片
FileSaveUtils.saveThumbnailFile(saveFile, path + "\\thumbnail\\",
saveFile.getName());
i++;
}
}
private Integer getUserID(HttpServletRequest request) {
User user = (User) request.getSession().getAttribute("user");
if (user != null) {
return user.getId();
}
return null;
}
}