日期:2014-05-16 浏览次数:20379 次
/** * * @功能模块: add * @方法说明: 添加一个对象 * @version: 1.0 * @param goodsType * GoodsTypeModel * @return Object spring 自动转换成 json 数据 * @throws */ @RequestMapping(params = "method=add") @ResponseBody public Object add(@ModelAttribute("goodsType") GoodsTypeModel goodsType) { return this.goodsTypeService.add(goodsType);// 返回的对象为:GoodsTypeModel }
/** * * @功能模块: add * @方法说明: 处理 method=add 请求, 添加商品信息 * @version: 1.0 * @param goodsInfo * 商品信息对象,由spring自动获取 * @param model * @return ModelMap 由spring自动生成json数据 * @throws IOException * @throws */ @RequestMapping(params = "method=add") //@ResponseBody public void add(@ModelAttribute("goodsInfo") GoodsInfoModel goodsInfo, HttpServletResponse response) throws IOException { if (!goodsInfo.getMpFile().isEmpty()) { goodsInfo.setGiImg(FileUploadUtil.saveFileUpload(goodsInfo.getMpFile(), GoodsInfoModel.DEFAULT_FILE_UPLOAD_DIR)); } this.goodsInfoService.add(goodsInfo); //return this.goodsInfoService.add(goodsInfo); // EXT 文件上传时,要返回的头部信息类型为 text/html, // 而用@ResponseBody返回的头部信息为application/json所以自动转换类型 // 由于本人能力有限,不知道如果要用@ResponseBody的时候怎么转换,呵呵 JsonUtil.printJSON(response, new Result()); } /* * 多文件上传时,请使用:DefaultMultipartHttpServletRequest public String add(@ModelAttribute("goodsInfo") GoodsInfoModel goodsInfo, DefaultMultipartHttpServletRequest multipartRequest){ List<MultipartFile> mpFiles = multipartRequest.getFiles("mpFile"); String fileNames = null; for(MultipartFile mpFile : mpFiles){ if( ! mpFile.isEmpty()){ if(fileNames!=null){ fileNames += "," + FileUploadUtil.saveFileUpload(mpFile, GoodsInfoModel.DEFAULT_FILE_UPLOAD_DIR); }else{ fileNames = FileUploadUtil.saveFileUpload(mpFile, GoodsInfoModel.DEFAULT_FILE_UPLOAD_DIR); } } } goodsInfo.setGiImg(fileNames); this.goodsInfoService.add(goodsInfo); return "redirect:/Product.do?method=list"; }*/
@RequestMapping(params = "method=login