package com.tydic.web; import java.io.File; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.apache.log4j.Logger; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.multipart.MultipartFile; import com.tydic.bean.UserInfo; import com.tydic.common.BaseController; import com.tydic.common.CommonKey; import com.tydic.common.ImgCut; import com.tydic.common.FileUploadUtil; import com.tydic.common.MD5; import com.tydic.service.CollectionService; import com.tydic.service.PostService; import com.tydic.service.ReplyService; import com.tydic.service.UserInfoService; @RequestMapping("/user") @Controller public class UserInfoController extends BaseController{ Logger logger = Logger.getLogger(UserInfoController.class); @Resource UserInfoService userService; /** * * @param x * @param y * @param h * @param w * @param userId * @param imageFile * @param req * @return * @throws Exception */ @RequestMapping(value = "/uploadImage",method = RequestMethod.POST) // @ResponseBody public String uploadImage(@RequestParam(value = "x") String x, @RequestParam(value = "y") String y, @RequestParam(value = "h") String h, @RequestParam(value = "w") String w, @RequestParam(value = "userId") String userId, @RequestParam(value = "showWidth") String showWidth, @RequestParam(value = "showHeight") String showHeight, @RequestParam(value = "imgFile") MultipartFile imageFile, HttpServletRequest req)throws Exception{ // String res = "";肥大胖 String realPath = req.getSession().getServletContext().getRealPath("/"); String resourcePath = "uploadImages/"; if(imageFile!=null && !imageFile.isEmpty()){ if(FileUploadUtil.allowUpload(imageFile.getContentType())){ String fileName = FileUploadUtil.rename(imageFile.getOriginalFilename()); int end = fileName.lastIndexOf("."); String saveName = fileName.substring(0,end); File dir = new File(realPath + resourcePath); if(!dir.exists()){ dir.mkdirs(); } System.out.println("----saveName----"+saveName); File file = new File(dir,saveName+"_src.jpg"); imageFile.transferTo(file); String srcImagePath = realPath + resourcePath + saveName; int imageX = Integer.parseInt(x); int imageY = Integer.parseInt(y); int imageH = Integer.parseInt(h); int imageW = Integer.parseInt(w); //这里开始截取操作 int imgWidth = Integer.parseInt(showWidth); int imgHeight = Integer.parseInt(showHeight); ImgCut.imgCut(srcImagePath,imageX,imageY,imageW,imageH,imgWidth,imgHeight); System.out.println("----image------"+imageX+"--"+imageY+"--"+imageW+"--"+imageH); System.out.println("----srcImagePath--------"+srcImagePath); req.getSession().setAttribute("imgSrc",resourcePath + saveName+"_src.jpg");//成功之后显示用 req.getSession().setAttribute("imgCut",resourcePath + saveName+"_cut.jpg");//成功之后显示用 UserInfo user = new UserInfo(); user.setUserId(Long.parseLong(userId)); user.setUserImage(resourcePath + saveName+"_cut.jpg"); userService.updateUserInfo(user); } } // return "forum/userDetail"; return "forum/loadImage"; // return res; } }

wade123 LV31
2019年1月3日
a812561851 LV8
2018年12月14日
wupujian LV17
2018年11月16日
秋鲫鱼 LV9
2018年6月20日
死了还要爱 LV19
2018年5月25日
halouhalou LV2
2018年5月11日
xyr10161 LV4
2018年4月19日
fenghuijun LV26
2018年4月8日
q09m10 LV3
2018年4月1日
醉微的阳光 LV1
2018年2月11日

微信网友_6914427966033920 LV4
2024年3月19日
bgkdgjkjfdkjv LV1
2022年5月11日
18784679855 LV8
2022年5月6日
zhy1989wz LV7
2022年3月15日
lyd19931203 LV21
2021年11月15日
qqdasa LV10
2021年6月16日
羞羞小子 LV13
2021年4月9日
13427720820 LV8
2021年4月1日
muimuimui LV9
2021年2月13日
MrReady LV14
2020年12月27日