Merge branch 'khj' into main
This commit is contained in:
commit
8b5ea2f3d5
@ -15,10 +15,14 @@
|
||||
package io.company.localhost.common.config;
|
||||
|
||||
import io.company.localhost.common.resolver.RequestToMapArgumentResolver;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
|
||||
import org.springframework.web.multipart.MultipartResolver;
|
||||
import org.springframework.web.multipart.support.StandardServletMultipartResolver;
|
||||
import org.springframework.web.servlet.LocaleResolver;
|
||||
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
@ -35,6 +39,9 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
public static final String WILD_CARD = "/**";
|
||||
|
||||
@Value("${filePath.boardfile}")
|
||||
private String boardFilePath;
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
// 여기서 인터셉터를 추가할 수 있음
|
||||
@ -47,6 +54,10 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
registry
|
||||
.addResourceHandler("/index.html")
|
||||
.addResourceLocations("classpath:/static/index.html", "/index.html");
|
||||
|
||||
//게시판 에디터 안 이미지 업로드 경로
|
||||
registry.addResourceHandler("/upload/img/board/**")
|
||||
.addResourceLocations("file:" + boardFilePath);
|
||||
}
|
||||
|
||||
// Controller의 파라미터를 처리할 Resolver 등록
|
||||
@ -82,4 +93,11 @@ public class WebMvcConfig implements WebMvcConfigurer {
|
||||
|
||||
return localeResolver;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MultipartResolver multipartResolver() {
|
||||
return new StandardServletMultipartResolver();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -14,9 +14,7 @@
|
||||
*************************************************************/
|
||||
package io.company.localhost.controller.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -25,8 +23,6 @@ import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import io.company.localhost.common.annotation.Member;
|
||||
import io.company.localhost.common.annotation.ParameterCheck;
|
||||
import io.company.localhost.common.annotation.ReqMap;
|
||||
@ -108,13 +104,11 @@ public class worddictController {
|
||||
* @return
|
||||
*/
|
||||
@Member
|
||||
@ParameterCheck
|
||||
@PostMapping("insertWord")
|
||||
public ApiResponse<Long> insertWord(@AuthenticationPrincipal MemberVo memberVo,@ReqMap MapDto map) {
|
||||
|
||||
//userId
|
||||
Long userId = AuthUtil.getUser().getId();
|
||||
String content = map.getString("content"); // content 추출
|
||||
//Long userId = AuthUtil.getUser().getId();
|
||||
//map.put("userId", userId);
|
||||
/////////로그인 미개발 ->임시
|
||||
map.put("userId", 1);
|
||||
|
||||
@ -0,0 +1,69 @@
|
||||
/************************************************************
|
||||
*
|
||||
* @packageName : io.company.localhost.controller.common
|
||||
* @fileName : ImageUploadController.java
|
||||
* @author : 공현지
|
||||
* @date : 25.01.16
|
||||
* @description :
|
||||
*
|
||||
* ===========================================================
|
||||
* DATE AUTHOR NOTE
|
||||
* -----------------------------------------------------------
|
||||
* 25.01.16 공현지 최초 생성
|
||||
*
|
||||
*************************************************************/
|
||||
package io.company.localhost.controller.common;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import io.company.localhost.common.annotation.ParameterCheck;
|
||||
import io.company.localhost.common.dto.ApiResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/img")
|
||||
@RequiredArgsConstructor
|
||||
public class ImageUploadController {
|
||||
|
||||
@Value("${filePath.boardfile}")
|
||||
private String boardFilePath;
|
||||
|
||||
@ParameterCheck
|
||||
@PostMapping("/upload")
|
||||
public ApiResponse<String> uploadImage(@RequestParam("file") MultipartFile file) throws IOException {
|
||||
|
||||
if (file.isEmpty()) {
|
||||
return ApiResponse.error(HttpStatus.BAD_REQUEST, "File is empty");
|
||||
}
|
||||
String originalFileName = file.getOriginalFilename();
|
||||
String fileExtension = originalFileName.substring(originalFileName.lastIndexOf("."));
|
||||
String fileName = UUID.randomUUID().toString() + fileExtension;
|
||||
Path filePath = Paths.get(boardFilePath, fileName);
|
||||
|
||||
Files.createDirectories(filePath.getParent());
|
||||
Files.write(filePath, file.getBytes());
|
||||
|
||||
String fileUrl = "upload/img/board/" + fileName;
|
||||
|
||||
return ApiResponse.ok(fileUrl);
|
||||
}
|
||||
|
||||
}
|
||||
@ -19,12 +19,8 @@ import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.github.pagehelper.PageHelper;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
|
||||
import io.company.localhost.common.dto.MapDto;
|
||||
import io.company.localhost.mapper.worddictyMapper;
|
||||
import io.company.localhost.utils.PageUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
@Service
|
||||
|
||||
@ -77,6 +77,9 @@ server:
|
||||
http-only: true
|
||||
secure: true
|
||||
same-site: NONE
|
||||
multipart:
|
||||
max-file-size: 10MB
|
||||
max-request-size: 10MB
|
||||
|
||||
logging:
|
||||
level:
|
||||
@ -89,3 +92,7 @@ logging:
|
||||
connection: off
|
||||
io.company: DEBUG
|
||||
io.company.localhost.mapper: off
|
||||
|
||||
|
||||
filePath:
|
||||
boardfile: C:\localhost-back\upload\img\board\
|
||||
Loading…
Reference in New Issue
Block a user