(Model model, String viewName, HttpServletResponse response)
| 86 | } |
| 87 | |
| 88 | private void render(Model model, String viewName, HttpServletResponse response) throws IOException { |
| 89 | String result = ""; |
| 90 | |
| 91 | response.setContentType("text/html"); |
| 92 | response.setCharacterEncoding("utf-8"); |
| 93 | PrintWriter out = response.getWriter(); |
| 94 | |
| 95 | // 1. 뷰의 내용을 한줄씩 읽어서 하나의 문자열로 만든다. |
| 96 | Scanner sc = new Scanner(new File(getResolvedViewName(viewName)), "utf-8"); |
| 97 | |
| 98 | while(sc.hasNextLine()) |
| 99 | result += sc.nextLine()+ System.lineSeparator(); |
| 100 | |
| 101 | // 2. model을 map으로 변환 |
| 102 | Map map = model.asMap(); |
| 103 | |
| 104 | // 3.key를 하나씩 읽어서 template의 ${key}를 value바꾼다. |
| 105 | Iterator it = map.keySet().iterator(); |
| 106 | |
| 107 | while(it.hasNext()) { |
| 108 | String key = (String)it.next(); |
| 109 | |
| 110 | // 4. replace()로 key를 value 치환한다. |
| 111 | result = result.replace("${"+key+"}", map.get(key)+""); |
| 112 | } |
| 113 | |
| 114 | // 5.렌더링 결과를 출력한다. |
| 115 | out.println(result); |
| 116 | } |
| 117 | } |
no test coverage detected