java用什么方式做aPP是上传图片的接口

两江总督首席码农 2015-10-10 02:29:50
java用什么方式做aPP上传图片的接口, 江湖救急啊
...全文
1259 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
你QQ多少啊,加你QQ详聊
  • 打赏
  • 举报
回复
你这是返回的什么数据
土豆你个番茄 2015-10-10
  • 打赏
  • 举报
回复

@RequestMapping("upload")
	public String uploadUserImage(HttpServletRequest req, @RequestParam(value = "file", required = false) MultipartFile file) {
		long st = new Date().getTime();
		log.info("Action开始");
		log.info("上传用户图像");
		String rootPath = req.getSession().getServletContext().getRealPath("/");
		HttpSession session = req.getSession();
		UserInfoBean tmpuser = (UserInfoBean) session.getAttribute("userInfo");

		UserInfoBean item = userService.loadUserInfoByUid(tmpuser.getUid());
		// 上传新的图像,删除原来的图像
		File df = new File(rootPath + item.getImgpath());
		if (df.exists()) {
			df.delete();
		}

		String fileName = file.getOriginalFilename();
		String[] strArr = fileName.split("\\.");

		fileName = new Date().getTime() + "." + strArr[strArr.length - 1];

		File targetFile = new File(rootPath + "file/userimg/app/", fileName);
		if (!targetFile.exists()) {
			targetFile.mkdirs();
		}
		// 保存
		try {
			file.transferTo(targetFile);
		} catch (Exception e) {
			e.printStackTrace();
		}

		UserInfoBean user = new UserInfoBean();
		user.setUid(tmpuser.getUid());

		user.setImgpath("file/userimg/app/" + fileName);
		log.info("Action调用修改用户信息方法");
		userService.updateUserInfo(user);

		log.info("Action结束");
		log.info("此方法耗费时间:" + (new Date().getTime() - st) + "毫秒");

		return "redirect:userCenter";
	}
  • 打赏
  • 举报
回复
不是,是和APP客户端做交互的,重客户端拿数据
土豆你个番茄 2015-10-10
  • 打赏
  • 举报
回复
MultipartFile file
土豆你个番茄 2015-10-10
  • 打赏
  • 举报
回复
和jsp一样的么

67,538

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧