mirror of
https://github.com/suhf/No1WMS.git
synced 2026-02-04 19:54:00 +09:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
package com.no1.wms.mypage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
@@ -17,19 +15,18 @@ import com.no1.wms.excel.EgovWebUtil;
|
||||
public class ImgService {
|
||||
|
||||
|
||||
@Autowired
|
||||
private ServletContext servletContext;
|
||||
|
||||
public void imgFileUplode(HttpServletRequest request, MultipartFile imageFile, String fileName) {
|
||||
|
||||
String storePathString = "";
|
||||
try {
|
||||
|
||||
storePathString = servletContext.getRealPath("/img/mypage/profile/");
|
||||
System.out.println("storePathString : " + storePathString);
|
||||
|
||||
ClassPathResource resource = new ClassPathResource("/static/img/mypage/profile");
|
||||
storePathString = resource.getFile().getAbsolutePath();
|
||||
//storePathString = System.getProperty("user.dir") + "/src/main/resources/static/img/mypage/profile";
|
||||
//System.out.println("storePathString : " + storePathString);
|
||||
//String path = ResourceUtils.getFile("classpath:static/img/mypage/profile/").toPath().toString();
|
||||
//String storePathString = path;
|
||||
//storePathString = path;
|
||||
|
||||
//System.out.println("storePathString : " + storePathString);
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -48,18 +45,29 @@ public class ImgService {
|
||||
|
||||
String newFileName = fileName;
|
||||
// 저장될 파일 경로 설정
|
||||
//String filePath = storePathString + File.separator + newFileName + "." + fileExt;
|
||||
String filePath = storePathString + newFileName + "." + fileExt;
|
||||
String filePath = storePathString + File.separator + newFileName + "." + fileExt;
|
||||
|
||||
try {
|
||||
// 동일한 파일명이 존재하는지 확인하고 있다면 기존 파일 삭제
|
||||
File existingFile = new File(filePath);
|
||||
if (existingFile.exists()) {
|
||||
existingFile.delete();
|
||||
}
|
||||
String jpg = storePathString + File.separator + newFileName + "." + "jpg";
|
||||
String png = storePathString + File.separator + newFileName + "." + "png";
|
||||
String jpeg = storePathString + File.separator + newFileName + "." + "jpeg";
|
||||
File existingJpgFile = new File(jpg);
|
||||
File existingPngFile = new File(png);
|
||||
File existingJpegFile = new File(jpeg);
|
||||
|
||||
String imgSrc = "";
|
||||
if(existingJpgFile.exists()) {
|
||||
existingJpgFile.delete();
|
||||
}else if(existingPngFile.exists()) {
|
||||
existingPngFile.delete();
|
||||
}else if(existingJpegFile.exists()) {
|
||||
existingJpegFile.delete();
|
||||
}
|
||||
|
||||
// 이미지를 지정된 경로에 저장
|
||||
imageFile.transferTo(new File(EgovWebUtil.filePathBlackList(filePath)));
|
||||
System.out.println("Image file saved at: " + filePath);
|
||||
//System.out.println("Image file saved at: " + filePath);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package com.no1.wms.mypage;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
|
||||
@@ -35,6 +39,39 @@ public class MypageController {
|
||||
AccountDto list = accountService.selectById(dto);
|
||||
m.addAttribute("list", list);
|
||||
|
||||
String id = list.getId();
|
||||
|
||||
ClassPathResource resource = new ClassPathResource("/static/img/mypage/profile");
|
||||
String storePathString;
|
||||
try {
|
||||
storePathString = resource.getFile().getAbsolutePath();
|
||||
String jpg = storePathString + File.separator + id + "." + "jpg";
|
||||
String png = storePathString + File.separator + id + "." + "png";
|
||||
String jpeg = storePathString + File.separator + id + "." + "jpeg";
|
||||
File existingJpgFile = new File(jpg);
|
||||
File existingPngFile = new File(png);
|
||||
File existingJpegFile = new File(jpeg);
|
||||
|
||||
String imgSrc = "";
|
||||
if(existingJpgFile.exists()) {
|
||||
imgSrc = "/resources/static/img/mypage/profile/"+ id +".jpg";
|
||||
//System.out.println("jpg");
|
||||
}else if(existingPngFile.exists()) {
|
||||
imgSrc = "/resources/static/img/mypage/profile/"+ id +".png";
|
||||
//System.out.println("png");
|
||||
}else if(existingJpegFile.exists()) {
|
||||
imgSrc = "/resources/static/img/mypage/profile/"+ id +".jpeg";
|
||||
//System.out.println("jpeg");
|
||||
}else {
|
||||
imgSrc = "/resources/static/img/mypage/profile/defaultimg.png";
|
||||
//System.out.println("default");
|
||||
}
|
||||
m.addAttribute("imgSrc", imgSrc);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return "mypage/mypage";
|
||||
}
|
||||
|
||||
@@ -52,11 +89,11 @@ public class MypageController {
|
||||
|
||||
@PostMapping("/mypage/uplodeImg")
|
||||
public String imgFileUplode(HttpServletRequest request, MultipartFile file) {
|
||||
System.out.println(file);
|
||||
//System.out.println(file);
|
||||
HttpSession session = request.getSession();
|
||||
AccountDto dto = (AccountDto) session.getAttribute("userData");
|
||||
String fileName = dto.getId();
|
||||
System.out.println(fileName);
|
||||
//System.out.println(fileName);
|
||||
imgService.imgFileUplode(request, file, fileName);
|
||||
|
||||
return "redirect:/mypage";
|
||||
|
||||
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
@@ -16,8 +16,9 @@
|
||||
<div class="container-fluid">
|
||||
<div class="row">
|
||||
<div class="col-md-4" style="text-align: center;">
|
||||
<img alt="Default Image" src="/main/webapp/img/mypage/profile/defaultimg.png" width="200" />
|
||||
<!-- <img alt="Default Image" src="/resources/static/img/mypage/defaultimg.png" width="200" /> -->
|
||||
<img alt="Default Image" src="${imgSrc}" width="200" />
|
||||
<!-- <img alt="Default Image" src="/resources/static/img/mypage/profile/${list.id}.png" width="200" /> -->
|
||||
<!-- -->
|
||||
<hr>
|
||||
<p><b>
|
||||
<span style="color: #6E6ED7; font-size: 20px;">${list.positionDto.name } </span>
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 764 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 58 KiB |
Reference in New Issue
Block a user