Bootstrap

基于javaweb+mysql的springboot校园二手交易平台二手市场(java+springboot+maven+mysql+freemarker)

基于javaweb+mysql的springboot校园二手交易平台二手市场(java+springboot+maven+mysql+freemarker)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的SpringBoot校园二手交易平台二手市场(java+springboot+maven+mysql+freemarker)

前台学生:

http://localhost:8088/home

student1 123456

student2 123456

student3 123456

功能:查看商品、求购、发布宝贝、评价等

后台管理员:

http://localhost:8088

admin 123456

功能:系统设置、物品及分类管理、学生管理、评论管理、新闻管理等

			Student student = studentService.findBySn(reportGoods.getStudent().getSn());
			if(student != null){
				reportGoods.setStudent(student);
			}
		}
		List<Goods> goodsList = null;
		if(reportGoods.getGoods() != null && reportGoods.getGoods().getName() != null){
			goodsList = goodsService.findListByName(reportGoods.getGoods().getName());
		}
		model.addAttribute("title", "物品举报列表");
		model.addAttribute("content", reportGoods.getContent());
		model.addAttribute("name", reportGoods.getGoods() == null ? null : reportGoods.getGoods().getName());
		model.addAttribute("sn", reportGoods.getStudent() == null ? null : reportGoods.getStudent().getSn());
		model.addAttribute("pageBean", reportGoodsService.findlist(pageBean, reportGoods,goodsList));
		return "admin/report/list";
	}
	
	

	
	/**
	 * 物品举报删除操作
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> delete(@RequestParam(name="id",required=true)Long id){
		reportGoodsService.delete(id);
		return Result.success(true);
	}
}


/**
 * 公用的上传类
 *
 */
@RequestMapping("/home/upload")
@Controller
public class HomeUploadController {

    @Value("${upload.photo.sufix}")
    private String uploadPhotoSufix;

    @Value("${upload.photo.maxsize}")
    private long uploadPhotoMaxSize;

    private Logger log = LoggerFactory.getLogger(HomeUploadController.class);

    /**
     * 图片统一上传类
     *
     * @param photo
     * @return
     */
    @RequestMapping(value = "/upload_photo", method = RequestMethod.POST)
    @ResponseBody
    public Result<String> uploadPhoto(@RequestParam(name = "photo", required = true) MultipartFile photo) {
        //判断文件类型是否是图片
        String originalFilename = photo.getOriginalFilename();
        //获取文件后缀
        String suffix = originalFilename.substring(originalFilename.lastIndexOf("."), originalFilename.length());
        if (!uploadPhotoSufix.contains(suffix.toLowerCase())) {
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		model.addAttribute("title", "添加物品分类");
		model.addAttribute("goodsCategorys", goodsCategoryService.findTopCategorys());
		return "admin/goods_category/add";
	}
	
	/**
	 * 商品分类添加表单提交
	 * @param goodsCategory
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> add(GoodsCategory goodsCategory){
		if(goodsCategory == null){
			return Result.error(CodeMsg.DATA_ERROR);
		}
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(goodsCategory);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(goodsCategory.getParent() != null && goodsCategory.getParent().getId() == null){
			goodsCategory.setParent(null);
		}
		//表示所有数据符合,可以添加到数据库
		if(goodsCategoryService.save(goodsCategory) ==null){
			return Result.error(CodeMsg.ADMIN_GOODSCATEGORY_ADD_ERROR);
		}
		return Result.success(true);
	}
	
	/**
	 * 编辑物品分类页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(@RequestParam(name="id",required=true)Long id,Model model){
		model.addAttribute("title", "编辑物品分类");
        return "admin/system/login";
    }

    /**
     * 用户登录提交表单处理方法
     *
     * @param request
     * @param user
     * @param cpacha
     * @return
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ResponseBody
    public Result<Boolean> login(HttpServletRequest request, User user, String cpacha) {
        if (user == null) {
            return Result.error(CodeMsg.DATA_ERROR);
        }
        //用统一验证实体方法验证是否合法
        CodeMsg validate = ValidateEntityUtil.validate(user);
        if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
            return Result.error(validate);
        }
        Object attribute = request.getSession().getAttribute("admin_login");
        if (attribute == null) {
            return Result.error(CodeMsg.SESSION_EXPIRED);
        }
        //表示session未失效,进一步判断用户填写的验证码是否正确
        //表示实体信息合法,开始验证验证码是否为空
        if (StringUtils.isEmpty(cpacha)) {
            return Result.error(CodeMsg.CPACHA_EMPTY);
        }
        //说明验证码不为空,从session里获取验证码
        if (!cpacha.equalsIgnoreCase(attribute.toString())) {
            return Result.error(CodeMsg.CPACHA_ERROR);
        }
        //表示验证码正确,开始查询数据库,检验密码是否正确
        User findByUsername = userService.findByUsername(user.getUsername());
        //判断是否为空
        if (findByUsername == null) {
            return Result.error(CodeMsg.ADMIN_USERNAME_NO_EXIST);
        }
        //表示用户存在,进一步对比密码是否正确
        if (!findByUsername.getPassword().equals(user.getPassword())) {
            return Result.error(CodeMsg.ADMIN_PASSWORD_ERROR);
        }
 *
 */
@RequestMapping("/admin/report")
@Controller
public class ReportController {

	@Autowired
	private GoodsService goodsService;
	@Autowired
	private StudentService studentService;
	@Autowired
	private ReportGoodsService reportGoodsService;
	
	/**
	 * 物品举报管理列表页面
	 * @param name
	 * @param pageBean
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/list")
	public String list(ReportGoods reportGoods,PageBean<ReportGoods> pageBean,Model model){
		if(reportGoods.getStudent() != null && reportGoods.getStudent().getSn() != null){
			Student student = studentService.findBySn(reportGoods.getStudent().getSn());
			if(student != null){
				reportGoods.setStudent(student);
			}
		}
		List<Goods> goodsList = null;
		if(reportGoods.getGoods() != null && reportGoods.getGoods().getName() != null){
			goodsList = goodsService.findListByName(reportGoods.getGoods().getName());
		}
		model.addAttribute("title", "物品举报列表");
		model.addAttribute("content", reportGoods.getContent());
		model.addAttribute("name", reportGoods.getGoods() == null ? null : reportGoods.getGoods().getName());
		model.addAttribute("sn", reportGoods.getStudent() == null ? null : reportGoods.getStudent().getSn());
		model.addAttribute("pageBean", reportGoodsService.findlist(pageBean, reportGoods,goodsList));
		return "admin/report/list";
	}
	
	

	
	/**
	 * 物品举报删除操作
	 * @param id
	
	/**
	 * 删除举报信息
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/delete_report",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> deleteReport(@RequestParam(name="id",required=true)Long id){
		ReportGoods reportGoods = reportGoodsService.find(id);
		if(reportGoods == null){
			return Result.error(CodeMsg.HOME_STUDENT_REPORTED_NO_EXIST);
		}
		Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
		if(reportGoods.getStudent().getId().longValue() != loginedStudent.getId().longValue()){
			return Result.error(CodeMsg.HOME_STUDENT_REPORTED_NO_EXIST);
		}
		reportGoodsService.delete(id);
		return Result.success(true);
	}
	
	/**
	 * 获取个人物品统计信息
	 * @return
	 */
	@RequestMapping(value="/get_stats",method=RequestMethod.POST)
	@ResponseBody
	public Result<Map<String, Integer>> getStats(){
		Map<String, Integer> ret = new HashMap<String, Integer>();
		Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
		List<Goods> findByStudent = goodsService.findByStudent(loginedStudent);
		Integer goodsTotal = findByStudent.size();//已发布的商品总数
		Integer soldGoodsTotal = 0;
		Integer downGoodsTotal = 0;
		Integer upGoodsTotal = 0;
		for(Goods goods : findByStudent){
			if(goods.getStatus() == Goods.GOODS_STATUS_SOLD){
				soldGoodsTotal++;
			}
			if(goods.getStatus() == Goods.GOODS_STATUS_DOWN){
        log.info("图片上传成功,保存位置:" + uploadPhotoPath + filename);
        return Result.success(filename);
    }
}

/**
 * 公用的上传类
 *
 */
@RequestMapping("/home/upload")
@Controller
public class HomeUploadController {

    @Value("${upload.photo.sufix}")
    private String uploadPhotoSufix;

    @Value("${upload.photo.maxsize}")
    private long uploadPhotoMaxSize;

    private Logger log = LoggerFactory.getLogger(HomeUploadController.class);

    /**
	}
	
	/**
	 * 友情链接编辑页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(Model model,@RequestParam(name="id",required=true)Long id){
		model.addAttribute("friendLink", friendLinkService.find(id));
		return "admin/friend_link/edit";
	}
	
	/**
	 * 编辑友情链接信息表单提交处理
	 * @param friendLink
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> edit(FriendLink friendLink){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(friendLink);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		//到这说明一切符合条件,进行数据库保存
		FriendLink findById = friendLinkService.find(friendLink.getId());
		//讲提交的友情链接信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容
		BeanUtils.copyProperties(friendLink, findById, "id","createTime","updateTime");
		if(friendLinkService.save(findById) == null){
			return Result.error(CodeMsg.ADMIN_FRIENDLINK_EDIT_ERROR);
		}
		operaterLogService.add("编辑友情链接:" + findById);
		return Result.success(true);
	}
	
	/**
	 * 删除友情链接
	 * @param id
	 * @return
				soldGoodsTotal++;
			}
			if(goods.getStatus() == Goods.GOODS_STATUS_DOWN){
				downGoodsTotal++;
			}
			if(goods.getStatus() == Goods.GOODS_STATUS_UP){
				upGoodsTotal++;
			}
		}
		ret.put("goodsTotal", goodsTotal);
		ret.put("soldGoodsTotal", soldGoodsTotal);
		ret.put("downGoodsTotal", downGoodsTotal);
		ret.put("upGoodsTotal", upGoodsTotal);
		return Result.success(ret);
	}
	
	/**
	 * 评论物品
	 * @param comment
	 * @return
	 */
	@RequestMapping(value="/comment",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> comment(Comment comment){
		CodeMsg validate = ValidateEntityUtil.validate(comment);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(comment.getGoods() == null || comment.getGoods().getId() == null){
			return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
		}
		Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
		Goods find = goodsService.findById(comment.getGoods().getId());
		if(find == null){
			return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
		}
		comment.setStudent(loginedStudent);
		if(commentService.save(comment) == null){
			return Result.error(CodeMsg.HOME_STUDENT_COMMENT_ADD_ERROR);
		}
		return Result.success(true);
	}
	
	/**
	 * 修改学生用户密码
	 * @param oldPwd
		model.addAttribute("goodsCategorys", goodsCategoryService.findTopCategorys());
		return "admin/goods_category/add";
	}
	
	/**
	 * 商品分类添加表单提交
	 * @param goodsCategory
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> add(GoodsCategory goodsCategory){
		if(goodsCategory == null){
			return Result.error(CodeMsg.DATA_ERROR);
		}
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(goodsCategory);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(goodsCategory.getParent() != null && goodsCategory.getParent().getId() == null){
			goodsCategory.setParent(null);
		}
		//表示所有数据符合,可以添加到数据库
		if(goodsCategoryService.save(goodsCategory) ==null){
			return Result.error(CodeMsg.ADMIN_GOODSCATEGORY_ADD_ERROR);
		}
		return Result.success(true);
	}
	
	/**
	 * 编辑物品分类页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(@RequestParam(name="id",required=true)Long id,Model model){
		model.addAttribute("title", "编辑物品分类");
		model.addAttribute("goodsCategorys", goodsCategoryService.findTopCategorys());
		model.addAttribute("goodsCategory", goodsCategoryService.findById(id));
		return "admin/goods_category/edit";
	}
	
	 * 角色编辑页面
	 * @param id
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String edit(@RequestParam(name="id",required=true)Long id,Model model){
		List<Menu> findAll = menuService.findAll();
		model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
		model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
		model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
		Role role = roleService.find(id);
		model.addAttribute("role", role);
		model.addAttribute("authorities",JSONArray.toJSON(role.getAuthorities()).toString());
		return "admin/role/edit";
	}
	
	/**
	 * 角色修改表单提交处理
	 * @param request
	 * @param role
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> edit(Role role){
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(role);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		Role existRole = roleService.find(role.getId());
		if(existRole == null){
			return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
		}
		existRole.setName(role.getName());
		existRole.setRemark(role.getRemark());
		existRole.setStatus(role.getStatus());
		existRole.setAuthorities(role.getAuthorities());
		if(roleService.save(existRole) == null){
			return Result.error(CodeMsg.ADMIN_ROLE_EDIT_ERROR);
		}
		log.info("编辑角色【"+role+"】");
		model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
		return "admin/menu/list";
	}
	
	/**
	 * 菜单添加页面
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		List<Menu> findAll = menuService.findAll();
		model.addAttribute("title","菜单列表");
		model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
		model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
		return "admin/menu/add";
	}
	
	/**
	 * 菜单添加提交表单处理
	 * @param menu
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> add(Menu menu){
		if(menu == null){
			Result.error(CodeMsg.DATA_ERROR);
		}
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(menu);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(menu.getParent() != null){
			if(menu.getParent().getId() == null){
				menu.setParent(null);
			}
		}
		//表示验证都通过,开始添加数据库
		if(menuService.save(menu) == null){
			Result.error(CodeMsg.ADMIN_MENU_ADD_ERROR);
					response.setCharacterEncoding("UTF-8");
					response.getWriter().write(JSON.toJSONString(CodeMsg.USER_SESSION_EXPIRED));
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				return false;
			}
			//说明是普通的请求,可直接重定向到登录页面
			//用户还未登录或者session失效,重定向到登录页面
			try {
				response.sendRedirect("/system/login");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return false;
		}
		log.info("该请求符合登录要求,放行" + requestURI);
		if(!StringUtil.isAjax(request)){
			//若不是ajax请求,则将菜单信息放入页面模板变量
			User user = (User)attribute;
			List<Menu> authorities = user.getRole().getAuthorities();
			request.setAttribute("userTopMenus", MenuUtil.getTopMenus(authorities));
			List<Menu> secondMenus = MenuUtil.getSecondMenus(user.getRole().getAuthorities());
			request.setAttribute("userSecondMenus", secondMenus);
			request.setAttribute("userThirdMenus", MenuUtil.getChildren(MenuUtil.getMenuIdByUrl(requestURI,secondMenus),authorities));
			request.setAttribute("siteName", siteConfig.getSiteName());
			request.setAttribute("siteUrl", siteConfig.getSiteUrl());
		}
		return true;
	}
}

	@RequestMapping(value="/edit_goods",method=RequestMethod.GET)
	public String publish(@RequestParam(name="id",required=true)Long id,Model model){
		Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
		Goods goods = goodsService.find(id, loginedStudent.getId());
		if(goods == null){
			model.addAttribute("msg", "物品不存在!");
			return "error/runtime_error";
		}
		model.addAttribute("goods", goods);
		return "home/student/edit_goods";
	}
	
	/**
	 * 物品编辑表单提交
	 * @param goods
	 * @return
	 */
	@RequestMapping(value="/edit_goods",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> editGoods(Goods goods){
		CodeMsg validate = ValidateEntityUtil.validate(goods);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(goods.getGoodsCategory() == null || goods.getGoodsCategory().getId() == null || goods.getGoodsCategory().getId().longValue() == -1){
			return Result.error(CodeMsg.HOME_STUDENT_PUBLISH_CATEGORY_EMPTY);
		}
		Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
		Goods existGoods = goodsService.find(goods.getId(), loginedStudent.getId());
		if(existGoods == null){
			return Result.error(CodeMsg.HOME_STUDENT_GOODS_NO_EXIST);
		}
		existGoods.setBuyPrice(goods.getBuyPrice());
		existGoods.setContent(goods.getContent());
		existGoods.setGoodsCategory(goods.getGoodsCategory());
		existGoods.setName(goods.getName());
		existGoods.setPhoto(goods.getPhoto());
		existGoods.setSellPrice(goods.getSellPrice());
		if(goodsService.save(existGoods) == null){
			return Result.error(CodeMsg.HOME_STUDENT_GOODS_EDIT_ERROR);
		}
		return Result.success(true);
	}
	
		if(menu == null){
			Result.error(CodeMsg.DATA_ERROR);
		}
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(menu);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(menu.getParent() != null){
			if(menu.getParent().getId() == null){
				menu.setParent(null);
			}
		}
		//表示验证都通过,开始添加数据库
		if(menuService.save(menu) == null){
			Result.error(CodeMsg.ADMIN_MENU_ADD_ERROR);
		}
		//数据库添加操作成功,记录日志
		operaterLogService.add("添加菜单信息【" + menu + "】");
		return Result.success(true);
	}
	
	/**
	 * 菜单编辑页面
	 * @param model
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String eidt(Model model,@RequestParam(name="id",required=true)Long id){
		List<Menu> findAll = menuService.findAll();
		model.addAttribute("title","菜单列表");
		model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
		model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
		model.addAttribute("menu",menuService.find(id));
		return "admin/menu/edit";
	}
	
	/**
	 * 菜单编辑页面表单提交处理
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(menu);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(menu.getParent() != null){
			if(menu.getParent().getId() == null){
				menu.setParent(null);
			}
		}
		//表示验证都通过,开始添加数据库
		if(menuService.save(menu) == null){
			Result.error(CodeMsg.ADMIN_MENU_ADD_ERROR);
		}
		//数据库添加操作成功,记录日志
		operaterLogService.add("添加菜单信息【" + menu + "】");
		return Result.success(true);
	}
	
	/**
	 * 菜单编辑页面
	 * @param model
	 * @param id
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.GET)
	public String eidt(Model model,@RequestParam(name="id",required=true)Long id){
		List<Menu> findAll = menuService.findAll();
		model.addAttribute("title","菜单列表");
		model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
		model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
		model.addAttribute("menu",menuService.find(id));
		return "admin/menu/edit";
	}
	
	/**
	 * 菜单编辑页面表单提交处理
	 * @param request
	 * @param menu
	 * @return
	 */
	@RequestMapping(value="/edit",method=RequestMethod.POST)
	@ResponseBody
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/list")
	public String list(GoodsCategory goodsCategory,PageBean<GoodsCategory> pageBean,Model model){
		model.addAttribute("title", "物品分类列表");
		model.addAttribute("name", goodsCategory.getName());
		model.addAttribute("pageBean", goodsCategoryService.findlist(pageBean, goodsCategory));
		return "admin/goods_category/list";
	}
	
	/**
	 * 物品分类添加页面
	 * @param goodsCategory
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.GET)
	public String add(Model model){
		model.addAttribute("title", "添加物品分类");
		model.addAttribute("goodsCategorys", goodsCategoryService.findTopCategorys());
		return "admin/goods_category/add";
	}
	
	/**
	 * 商品分类添加表单提交
	 * @param goodsCategory
	 * @return
	 */
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> add(GoodsCategory goodsCategory){
		if(goodsCategory == null){
			return Result.error(CodeMsg.DATA_ERROR);
		}
		//用统一验证实体方法验证是否合法
		CodeMsg validate = ValidateEntityUtil.validate(goodsCategory);
		if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
			return Result.error(validate);
		}
		if(goodsCategory.getParent() != null && goodsCategory.getParent().getId() == null){
			goodsCategory.setParent(null);
		}
		//表示所有数据符合,可以添加到数据库
		if(goodsCategoryService.save(goodsCategory) ==null){

/**
 * 学生中心控制器
 *
 */
@RequestMapping("/home/student")
@Controller
public class HomeStudentController {

	@Autowired
	private GoodsCategoryService goodsCategoryService;
	@Autowired
	private StudentService studentService;
	@Autowired
	private GoodsService goodsService;
	@Autowired
	private WantedGoodsService wantedGoodsService;
	@Autowired
	private ReportGoodsService reportGoodsService;
	@Autowired
	private CommentService commentService;
	/**
	 * 学生登录主页
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public String index(Model model){
		Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
		model.addAttribute("goodsList", goodsService.findByStudent(loginedStudent));
		model.addAttribute("wantedGoodsList", wantedGoodsService.findByStudent(loginedStudent));
		model.addAttribute("reportGoodsList", reportGoodsService.findByStudent(loginedStudent));
		return "home/student/index";
	}
	
	/**
	 * 修改个人信息提交表单
	 * @param student
	 * @return
	 */
	@RequestMapping(value="/edit_info",method=RequestMethod.POST)
	@ResponseBody
	public Result<Boolean> editInfo(Student student){
		Student loginedStudent = (Student)SessionUtil.get(SessionConstant.SESSION_STUDENT_LOGIN_KEY);
		loginedStudent.setAcademy(student.getAcademy());
            codeMsg.setMsg("图片大小不能超过" + (uploadPhotoMaxSize / 1024) + "M");
            return Result.error(codeMsg);
        }

        //准备保存文件
        String uploadPhotoPath = PathUtil.newInstance().getUploadPhotoPath();
        File filePath = new File(uploadPhotoPath);
        if (!filePath.exists()) {
            //若不存在文件夹,则创建一个文件夹
            filePath.mkdir();
        }
        filePath = new File(uploadPhotoPath + "/" + StringUtil.getFormatterDate(new Date(), "yyyyMMdd"));
        //判断当天日期的文件夹是否存在,若不存在,则创建
        if (!filePath.exists()) {
            //若不存在文件夹,则创建一个文件夹
            filePath.mkdir();
        }
        String filename = StringUtil.getFormatterDate(new Date(), "yyyyMMdd") + "/" + System.currentTimeMillis() + suffix;
        try {
            photo.transferTo(new File(uploadPhotoPath + "/" + filename));
        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        log.info("图片上传成功,保存位置:" + uploadPhotoPath + filename);
        return Result.success(filename);
    }
}

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

;