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