110 lines
4.4 KiB
Java
110 lines
4.4 KiB
Java
/************************************************************
|
|
*
|
|
* @packageName : io.company.localhost.common.config
|
|
* @fileName : WebMvcConfig.java
|
|
* @author : 조인제
|
|
* @date : 24.12.06
|
|
* @description :
|
|
*
|
|
* ===========================================================
|
|
* DATE AUTHOR NOTE
|
|
* -----------------------------------------------------------
|
|
* 24.12.06 조인제 최초 생성
|
|
*
|
|
*************************************************************/
|
|
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;
|
|
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
|
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
|
import org.springframework.web.servlet.i18n.SessionLocaleResolver;
|
|
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.TimeZone;
|
|
|
|
@Configuration
|
|
public class WebMvcConfig implements WebMvcConfigurer {
|
|
|
|
public static final String WILD_CARD = "/**";
|
|
|
|
@Value("${filePath.boardfile}")
|
|
private String boardFilePath;
|
|
|
|
@Value("${filePath.profile}")
|
|
private String uploadPath;
|
|
|
|
@Override
|
|
public void addInterceptors(InterceptorRegistry registry) {
|
|
// 여기서 인터셉터를 추가할 수 있음
|
|
// 예: registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
|
|
}
|
|
|
|
// 리소스 핸들러를 설정
|
|
@Override
|
|
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
|
registry
|
|
.addResourceHandler("/index.html")
|
|
.addResourceLocations("classpath:/static/index.html", "/index.html");
|
|
|
|
//게시판 에디터 안 이미지 업로드 경로
|
|
registry.addResourceHandler("/upload/img/board/**")
|
|
.addResourceLocations("file:" + boardFilePath);
|
|
//프로필 이미지 업로드 경로
|
|
registry.addResourceHandler("/upload/img/profile/**")
|
|
.addResourceLocations("file:" + uploadPath);
|
|
}
|
|
|
|
// Controller의 파라미터를 처리할 Resolver 등록
|
|
@Override
|
|
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
|
|
// RequestToMapArgumentResolver는 요청을 Map으로 변환하여 파라미터로 받을 수 있도록 설정
|
|
resolvers.add(new RequestToMapArgumentResolver());
|
|
}
|
|
|
|
// 클라이언트가 원하는 미디어 타입에 따라 반환할 타입 설정
|
|
@Override
|
|
public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
|
|
// 기본 응답 타입을 JSON으로 설정
|
|
configurer.defaultContentType(MediaType.APPLICATION_JSON)
|
|
.ignoreAcceptHeader(true) // Accept 헤더를 무시하고 기본값을 JSON으로 설정
|
|
|
|
// "mediaType" 파라미터 값에 따라 반환할 미디어 타입 설정
|
|
.favorParameter(true) // 요청 파라미터로 mediaType을 사용할 수 있게 설정
|
|
.parameterName("mediaType") // 파라미터 이름 설정
|
|
.mediaType("xml", MediaType.APPLICATION_XML) // "mediaType=xml"이면 XML 응답
|
|
.mediaType("json", MediaType.APPLICATION_JSON); // "mediaType=json"이면 JSON 응답
|
|
}
|
|
|
|
//세션을 이용하여 언어와 시간대 설정
|
|
@Bean
|
|
LocaleResolver localeResolver() {
|
|
Locale defaultLocale = Locale.getDefault();
|
|
TimeZone defaultTimeZone = TimeZone.getDefault();
|
|
|
|
SessionLocaleResolver localeResolver = new SessionLocaleResolver();
|
|
localeResolver.setDefaultLocale(defaultLocale);
|
|
localeResolver.setDefaultTimeZone(defaultTimeZone);
|
|
|
|
return localeResolver;
|
|
}
|
|
|
|
@Bean
|
|
public MultipartResolver multipartResolver() {
|
|
return new StandardServletMultipartResolver();
|
|
}
|
|
|
|
|
|
}
|