업무별 URL매핑용 어노테이션 추가
parent
ad1a1665dc
commit
d48e4ca4bf
@ -0,0 +1,12 @@
|
||||
package cokr.xit.fims.task;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.METHOD)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Task {
|
||||
String[] value();
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cokr.xit.fims.task;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.DelegatingWebMvcConfiguration;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
|
||||
@Configuration
|
||||
public class TaskMvcConfig extends DelegatingWebMvcConfiguration {
|
||||
|
||||
@Override
|
||||
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
|
||||
return new TaskRequestMappingHandlerMapping();
|
||||
}
|
||||
|
||||
@Bean
|
||||
TaskRequestMappingHandlerMapping taskRequestMappingHandlerMapping() {
|
||||
return new TaskRequestMappingHandlerMapping();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package cokr.xit.fims.task;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo.BuilderConfiguration;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
public class TaskRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public RequestMappingInfo getMappingForMethod(Method method, Class<?> handlerType) {
|
||||
|
||||
RequestMappingInfo info = super.getMappingForMethod(method, handlerType);
|
||||
|
||||
Task task = AnnotatedElementUtils.findMergedAnnotation(method, Task.class);
|
||||
|
||||
if(task != null && info != null) {
|
||||
return createRequestMappingInfo(task, method, info);
|
||||
} else {
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected RequestMappingInfo createRequestMappingInfo(Task task, Method method,
|
||||
RequestMappingInfo info) {
|
||||
|
||||
String[] prefix = task.value();
|
||||
|
||||
RequestMapping rm = AnnotatedElementUtils.findMergedAnnotation(method, RequestMapping.class);
|
||||
|
||||
Set<String> olds0 = info.getPatternValues();
|
||||
String[] olds = olds0.toArray(new String[olds0.size()]);
|
||||
String[] news = new String[prefix.length*olds.length];
|
||||
for(int i=0;i < prefix.length; i++) {
|
||||
for(int j=0;j < olds.length; j++) {
|
||||
String newPattern = "/"+prefix[i]+olds[j];
|
||||
news[i*(olds.length)+j] = newPattern;
|
||||
}
|
||||
}
|
||||
|
||||
BuilderConfiguration bc = new RequestMappingInfo.BuilderConfiguration();
|
||||
bc.setContentNegotiationManager(super.getContentNegotiationManager());
|
||||
bc.setPatternParser(super.getPatternParser());
|
||||
|
||||
return RequestMappingInfo
|
||||
.paths(super.resolveEmbeddedValuesInPatterns(news))
|
||||
.mappingName(rm.name())
|
||||
.methods(rm.method())
|
||||
.params(rm.params())
|
||||
.headers(rm.headers())
|
||||
.consumes(rm.consumes())
|
||||
.produces(rm.produces())
|
||||
.options(bc)
|
||||
.build();
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue