View와 ViewResolver에 대한 재설계 반영 및 예외처리 로직 추가

This commit is contained in:
Terry Chang
2018-10-23 16:22:26 +09:00
parent 4ad17e3ca8
commit 118a2de5b7
7 changed files with 139 additions and 117 deletions

View File

@@ -5,16 +5,22 @@ import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
import com.terry.xplatform.config.xplatform.web.XplatformView;
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(value={DataAccessException.class})
public ModelAndView processDataAccessException(DataAccessException ex){
public XplatformView processDataAccessException(DataAccessException ex){
/*
ModelAndView modelAndView = new ModelAndView();
modelAndView.addObject("ErrorCode", "-1");
modelAndView.addObject("ErrorMsg", ex.getMessage());
modelAndView.setViewName("errorView");
return modelAndView;
*/
XplatformView xplatformView = new XplatformView("30", ex.getMessage());
return xplatformView;
}
@ExceptionHandler(value={Exception.class})

View File

@@ -2,6 +2,6 @@ package com.terry.xplatform.config.xplatform;
import com.tobesoft.xplatform.tx.PlatformType;
public class XplatformConstants implements PlatformType {
public interface XplatformConstants extends PlatformType {
public static final String CONTENT_TYPE_CSV = "csv";
}

View File

@@ -11,10 +11,9 @@ import java.util.Map.Entry;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.util.StringUtils;
import org.springframework.validation.BeanPropertyBindingResult;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.servlet.view.AbstractTemplateView;
import com.terry.xplatform.config.utils.XplatformReflectionUtils;
import com.terry.xplatform.config.xplatform.XplatformConstants;
@@ -27,7 +26,7 @@ import com.tobesoft.xplatform.data.VariableList;
import com.tobesoft.xplatform.data.datatype.PlatformDataType;
import com.tobesoft.xplatform.tx.HttpPlatformResponse;
public class XplatformView extends AbstractTemplateView {
public class XplatformView implements View {
/**
* Xplatform의 작업결과가 성공적이었을때의 ErrorCode 값을 설정한다
@@ -50,17 +49,26 @@ public class XplatformView extends AbstractTemplateView {
}
@Override
protected void renderMergedTemplateModel(Map<String, Object> model, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
public String getContentType() {
// TODO Auto-generated method stub
String contentType = StringUtils.hasText((String)model.get("contentType")) ? (String)model.get("contentType") : XplatformConstants.CONTENT_TYPE_XML;
model.remove("contentType");
return null;
}
@Override
public void render(Map<String, ?> model, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// TODO Auto-generated method stub
String contentType = request.getHeader("Content-Type").startsWith("text/xml;") ? XplatformConstants.CONTENT_TYPE_XML
: request.getHeader("Content-Type");
if(contentType == XplatformConstants.CONTENT_TYPE_XML) {
VariableList variableList = new VariableList();
DataSetList dataSetList = new DataSetList();
HttpPlatformResponse httpPlatformResponse = new HttpPlatformResponse(httpServletResponse, XplatformConstants.CONTENT_TYPE_XML);
HttpPlatformResponse httpPlatformResponse = new HttpPlatformResponse(response, XplatformConstants.CONTENT_TYPE_XML);
for(Entry<String, Object> entry : model.entrySet()) {
if(model != null) {
for(Entry<String, ?> entry : model.entrySet()) {
String key = entry.getKey();
Object object = entry.getValue();
if(object instanceof Collection) {
@@ -109,6 +117,7 @@ public class XplatformView extends AbstractTemplateView {
if(!model.containsKey("ErrorMsg")) {
variableList.add("ErrorMsg", ERROR_MSG_VALUE);
}
}
PlatformData platformData = new PlatformData();
platformData.setVariableList(variableList);
@@ -119,8 +128,6 @@ public class XplatformView extends AbstractTemplateView {
} else if(contentType == XplatformConstants.CONTENT_TYPE_CSV) {
}
}
/**
@@ -313,5 +320,4 @@ public class XplatformView extends AbstractTemplateView {
return result;
}
}

View File

@@ -1,21 +1,30 @@
package com.terry.xplatform.config.xplatform.web;
import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
import org.springframework.web.servlet.view.AbstractUrlBasedView;
import java.util.Locale;
public class XplatformViewResolver extends AbstractTemplateViewResolver {
import org.springframework.core.Ordered;
import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
public class XplatformViewResolver implements ViewResolver, Ordered {
private int order = Ordered.LOWEST_PRECEDENCE;
@Override
protected Class getViewClass() {
public View resolveViewName(String viewName, Locale locale) throws Exception {
// TODO Auto-generated method stub
return XplatformView.class;
XplatformView xplatformView = new XplatformView();
return xplatformView;
}
@Override
protected AbstractUrlBasedView buildView(String viewName) throws Exception {
public int getOrder() {
// TODO Auto-generated method stub
XplatformView view = (XplatformView)super.buildView(viewName);
return view;
return order;
}
public void setOrder(int order) {
this.order = order;
}
}

View File

@@ -31,6 +31,7 @@ public class SampleServiceImpl implements SampleService {
@Override
public List<SampleVO> list(SampleDefaultVO sampleDefaultVO) throws DataAccessException {
// TODO Auto-generated method stub
// throw new DataAccessException("Test DataAccessException Message") {};
List<SampleVO> result = sampleDAO.selectSampleList(sampleDefaultVO);
return result;
}

View File

@@ -28,7 +28,7 @@ public class SampleController {
@Autowired
SampleService sampleService;
@RequestMapping("/egovSampleSelect")
@RequestMapping("egovSampleSelect")
public void list(Model model
, SampleVO sampleVO
, @RequestVariable SampleVO requestVariableSampleVO