본문 바로가기

STUDY REVIEW/클린코드 독서스터디

Clean Code - 2주차 스터디 후기

5장 형식 맞추기

@RequestMapping(value = "/rowDataMngr/rowDataMngrIndex")
public ModelAndView getRowData(HttpServletRequest request, HttpServletResponse response) throws Exception{

  ModelAndView model = new ModelAndView("/view/rowDataDownMngr/row_data_mngr_index.jsp");
  HashMap<String, Object> inMap = new HashMap<String, Object>();

  try {
  
    bindForMap(request, inMap);
    Map<String, Object> companyInfoMap = rowDataMngrService.getCompanyList(inMap);
    model.addObject("companyInfo", companyInfo.get("companyList"));
    
  } catch (BizExceptionProperties ex) {
  	model.addObject("result", ex.getMsg());
  } catch (Exception ex) {
  	log.error("", ex);
  	model.addObject("result", "호출 중 오류가 발생했습니다.");
  }
  return model;
}


6장 객체와 자료 구조

@RequestMapping(value = "/statisticsMngr/statistics", method = RequestMethod.POST)
public ModelAndView statistics(HttpServletRequest request, HttpServletResponse response) throws JSONException {

  ModelAndView model = new ModelAndView(jsonView);
  HashMap<String, Object> inMap = new HashMap<String, Object>();
  JSONObject json = new JSONObject();

  try {
  
    bindForMap(request, inMap);
    String messageText = "";

    if(inMap.get("search_option").toString().equals("Service")){
      messageText = "Service";
      statisticsMngrService.callStatisticService(inMap);
    } else {
      messageText = "etc";
      statisticsMngrService.callStatisticEtc(inMap);
    }

  	json.put("message", messageText + " 통계가 완료되었습니다.");		

  } catch (Exception ex) {
  	log.error("", ex);
  	json.put("message", "통계를 실패하였습니다.");
  	ex.printStackTrace();
  }
  model.addObject("json", json.toString());
  return model;
}


7장 오류처리

@RequestMapping(value = "/login")
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {

  ModelAndView model = null;

  try {

    HashMap<String, Object> inMap = new HashMap<String, Object>();
    bindForMap(request, inMap);

    HashMap<String, Object> resultMap = loginService.selectMember(inMap);
    loginUtil.LoginInfo(resultMap.get("ID").toString());

  } catch (FrameworkException ex) {
    model = new ModelAndView(FrameworkConstants.MESSAGE_URL);
    model.addObject("result", ex.getMsg());
    ex.printStackTrace();
  } catch (BizExceptionProperties ex) {
    model = new ModelAndView(FrameworkConstants.MESSAGE_URL);
    model.addObject("result", ex.getMsg());
  } catch (SQLException ex) {
    model = new ModelAndView(FrameworkConstants.MESSAGE_URL);
    model.addObject("result", "로그인 중 오류가 발생했습니다.");
    ex.printStackTrace();
  } catch (Exception ex) {
    model = new ModelAndView(FrameworkConstants.MESSAGE_URL);
    model.addObject("result", "로그인 중 오류가 발생했습니다.");
    ex.printStackTrace();
  }
  return model;
}


8장 경계- Clean Code 인용

public class LogTest {
     private Logger logger;

     @Before
     public void initialize() {
         logger = Logger.getLogger("logger");
         logger.removeAllAppenders();
         Logger.getRootLogger().removeAllAppenders();
     }

     @Test
     public void basicLogger() {
         BasicConfigurator.configure();
         logger.info("basicLogger");
     }

     @Test
     public void addAppenderWithStream() {
         logger.addAppender(new ConsoleAppender(
             new PatternLayout("%p %t %m%n"),
             ConsoleAppender.SYSTEM_OUT));
         logger.info("addAppenderWithStream");
     }

     @Test
     public void addAppenderWithoutStream() {
         logger.addAppender(new ConsoleAppender(
             new PatternLayout("%p %t %m%n")));
         logger.info("addAppenderWithoutStream");
     }
 }

 

'STUDY REVIEW > 클린코드 독서스터디' 카테고리의 다른 글

Clean Code - (3 - 2)주차  (0) 2021.05.21
Clean Code - 3주차  (0) 2021.05.21
Clean Code - 2주차  (0) 2021.05.10
Clean Code - 1주차 스터디 후기  (0) 2021.05.03
Clean Code - 1주차  (0) 2021.05.03