XplatformArgumentResolver 클래스에 @RequestDataSetList 어노테이션 반영
This commit is contained in:
@@ -40,22 +40,22 @@ import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
public class XplatformArgumentResolver implements HandlerMethodArgumentResolver {
|
||||
|
||||
|
||||
/**
|
||||
* DataSetList 객체를 HttpServletRequest의 setAttribute 메소드를 이용해서 저장할 때 사용되는 이름
|
||||
*/
|
||||
private final String DATASETLIST_NAME;
|
||||
|
||||
|
||||
/**
|
||||
* VariableList 객체를 HttpServletRequest의 setAttribute 메소드를 이용해서 저장할 때 사용되는 이름
|
||||
*/
|
||||
private final String VARIABLELIST_NAME;
|
||||
|
||||
|
||||
public XplatformArgumentResolver() {
|
||||
this.DATASETLIST_NAME = "dataSetList";
|
||||
this.VARIABLELIST_NAME = "variableList";
|
||||
}
|
||||
|
||||
|
||||
public XplatformArgumentResolver(String dataSetListName, String variableListName) {
|
||||
this.DATASETLIST_NAME = dataSetListName;
|
||||
this.VARIABLELIST_NAME = variableListName;
|
||||
@@ -65,29 +65,30 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
public boolean supportsParameter(MethodParameter parameter) {
|
||||
// TODO Auto-generated method stub
|
||||
boolean result = false;
|
||||
|
||||
if(parameter.hasParameterAnnotation(RequestDataSet.class)){
|
||||
if(parameter.hasParameterAnnotation(RequestDataSetList.class)){
|
||||
result = true;
|
||||
}else if(parameter.hasParameterAnnotation(RequestDataSet.class)){
|
||||
result = true;
|
||||
}else if(parameter.hasParameterAnnotation(RequestVariable.class)){
|
||||
result = true;
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
|
||||
Class<?> type = parameter.getParameterType();
|
||||
Annotation[] annotations = parameter.getParameterAnnotations();
|
||||
HttpServletRequest request = (HttpServletRequest)webRequest.getNativeRequest();
|
||||
// HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class);
|
||||
// PlatformRequest platformRequest = new HttpPlatformRequest(request, "utf-8");
|
||||
|
||||
|
||||
DataSetList dataSetList = null;
|
||||
VariableList variableList = null;
|
||||
|
||||
|
||||
// 관련 처리를 할때마다 매번 Request의 Body에 있는 DataSetList와 VariableList를 만들면 오버헤드 소지가 있어서
|
||||
// 처음에 한번만 읽고 DataSetList와 VariableList를 HttpServletRequest에 setAttribute를 통해 저장을 한 뒤에
|
||||
// 다시 읽을때는 Request의 Body를 읽는게 아니라 저장되어 있는 것을 다시 읽어서 재활용한다
|
||||
@@ -97,20 +98,20 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
PlatformData platformData = platformRequest.getData();
|
||||
dataSetList = platformData.getDataSetList();
|
||||
variableList = platformData.getVariableList();
|
||||
|
||||
|
||||
request.setAttribute(DATASETLIST_NAME, dataSetList);
|
||||
request.setAttribute(VARIABLELIST_NAME, variableList);
|
||||
} else {
|
||||
dataSetList = (DataSetList)request.getAttribute(DATASETLIST_NAME);
|
||||
variableList = (VariableList)request.getAttribute(VARIABLELIST_NAME);
|
||||
}
|
||||
|
||||
|
||||
Object result = null;
|
||||
|
||||
|
||||
|
||||
|
||||
for(Annotation annotation : annotations){
|
||||
Class<? extends Annotation> annotationClass = annotation.annotationType();
|
||||
|
||||
|
||||
if(annotationClass.equals(RequestDataSetList.class)){ // @RequestDataSetList 어노테이션에 대한 처리(이 어노테이션은 DataSetList 클래스객체만 파라미터 타입으로 받을 수 있다)
|
||||
if(type.equals(DataSetList.class)) {
|
||||
result = dataSetList;
|
||||
@@ -123,14 +124,14 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
if(!StringUtils.hasText(dataSetName)) { // DataSet 이름이 빠진것이므로 이거는 예외처리 진행하자
|
||||
result = WebArgumentResolver.UNRESOLVED;
|
||||
} else {
|
||||
DataSet dataSet = dataSetList.get(dataSetName);
|
||||
DataSet dataSet = dataSetList.get(dataSetName);
|
||||
if(type.equals(DataSet.class)) { // DataSet 파라미터 타입으로 받을 경우는 해당 이름으로 DataSet을 찾아서 이를 return 해주면 된다
|
||||
result = dataSet;
|
||||
} else { // DataSet 클래스 객체는 Collection 인터페이스 계열 클래스들만 변환이 가능하기 때문에 이에 대한 체크
|
||||
if(Collection.class.isAssignableFrom(type)) {
|
||||
// Type[] typeArray = ((ParameterizedType)parameter.getGenericParameterType()).getActualTypeArguments();
|
||||
// Type[] typeArray = ((ParameterizedType)parameter.getGenericParameterType()).getActualTypeArguments();
|
||||
// Class<?> genericClassType = (Class<?>) ((ParameterizedType)parameter.getGenericParameterType()).getActualTypeArguments()[0];
|
||||
|
||||
|
||||
Type genericType = ((ParameterizedType)parameter.getGenericParameterType()).getActualTypeArguments()[0];
|
||||
Class<?> genericClass = null;
|
||||
if(genericType instanceof Class) {
|
||||
@@ -146,7 +147,7 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// XplatformReflectionUtils.convertDataSetToCollection 메소드로 변환할 수 없는 타입일 경우 null이 return 되기 때문에 이에 대한 처리
|
||||
if(result == null) {
|
||||
result = WebArgumentResolver.UNRESOLVED;
|
||||
@@ -181,7 +182,7 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
}
|
||||
} else { // 특정 변수 이름이 없으면 VO로 매핑하는 것이기 때문에 오히려 이런 경우 자바의 데이터타입과는 매핑을 할 수 없다
|
||||
List<String> keyList = variableList.keyList();
|
||||
|
||||
|
||||
if(Collection.class.isAssignableFrom(type)) {
|
||||
Collection collectionResult = null;
|
||||
if(type.isInterface()) {
|
||||
@@ -193,11 +194,11 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
} else {
|
||||
collectionResult = (Collection)type.newInstance();
|
||||
}
|
||||
|
||||
|
||||
for(String key : keyList) {
|
||||
collectionResult.add(variableList.getObject(key));
|
||||
}
|
||||
|
||||
|
||||
result = collectionResult;
|
||||
} else if(Map.class.isAssignableFrom(type)) {
|
||||
Map<String, Object> mapResult = null;
|
||||
@@ -206,24 +207,24 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
} else {
|
||||
mapResult = (Map<String, Object>)type.newInstance();
|
||||
}
|
||||
|
||||
|
||||
for(String key : keyList) {
|
||||
mapResult.put(key, variableList.getObject(key));
|
||||
}
|
||||
|
||||
|
||||
result = mapResult;
|
||||
} else {
|
||||
// 객체로 변환하는 과정에서 예외가 발생하면 지원하지 않는 타입이기 때문에 그에 대한 처리를 한다
|
||||
try {
|
||||
|
||||
|
||||
Object obj = type.newInstance();
|
||||
|
||||
|
||||
for(String key : keyList) {
|
||||
Field keyField = ReflectionUtils.findField(type, key);
|
||||
ReflectionUtils.makeAccessible(keyField);
|
||||
|
||||
|
||||
Class<?> keyFieldType = keyField.getType();
|
||||
|
||||
|
||||
if(keyFieldType == int.class) {
|
||||
keyField.setInt(obj, variableList.getInt(key));
|
||||
} else if(keyFieldType == Integer.class) {
|
||||
@@ -248,7 +249,7 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
keyField.set(obj, variableList.getObject(key));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
result = obj;
|
||||
} catch(Exception e) {
|
||||
result = WebArgumentResolver.UNRESOLVED;
|
||||
@@ -256,9 +257,9 @@ public class XplatformArgumentResolver implements HandlerMethodArgumentResolver
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,19 +13,21 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
|
||||
import com.terry.xplatform.config.xplatform.annotation.RequestDataSet;
|
||||
import com.terry.xplatform.config.xplatform.annotation.RequestDataSetList;
|
||||
import com.terry.xplatform.config.xplatform.annotation.RequestVariable;
|
||||
import com.terry.xplatform.service.SampleService;
|
||||
import com.terry.xplatform.vo.SampleVO;
|
||||
import com.tobesoft.xplatform.data.DataSetList;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Controller
|
||||
@Slf4j
|
||||
public class SampleController {
|
||||
|
||||
|
||||
@Autowired
|
||||
SampleService sampleService;
|
||||
|
||||
|
||||
@RequestMapping("/egovSampleSelect")
|
||||
public void list(Model model
|
||||
, SampleVO sampleVO
|
||||
@@ -38,7 +40,7 @@ public class SampleController {
|
||||
List<SampleVO> sampleList = sampleService.list(sampleVO);
|
||||
model.addAttribute("ds_output", sampleList);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@RequestMapping("/egovSampleSelect")
|
||||
public void list(HttpServletRequest httpServletRequest) {
|
||||
@@ -46,11 +48,13 @@ public class SampleController {
|
||||
String recordCountPerPage = httpServletRequest.getParameter("recordCountPerPage");
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
@RequestMapping("/egovSampleModify")
|
||||
public void modify(@RequestDataSet(name="ds_input")ArrayList<SampleVO> dataSet
|
||||
, @RequestDataSet(name="ds_input")List<Map<String, Object>> dataSetMap
|
||||
, @RequestDataSet(name="ds_input")Set<SampleVO> dataHashSet) {
|
||||
, @RequestDataSet(name="ds_input")Set<SampleVO> dataHashSet
|
||||
, @RequestDataSetList DataSetList dataSetList) {
|
||||
logger.info("modify");
|
||||
sampleService.modify(dataSet);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user