Spring Boot 시작하기
- #9. Srping Boot JSP ModelAndView 설정하기
8장에 이어 ModelAndView 를 이용해 jstl로 데이터를 연동하는 진행해 보겠습니다.
ModelAndViewTestController.java
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 |
package com.example.controller;import java.util.ArrayList;import java.util.List;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.servlet.ModelAndView;@Controllerpublic class ModelAndViewTestController { public ModelAndView root() { ModelAndView mv = new ModelAndView(); List<string> listTest = new ArrayList<string>(); listTest.add("test1"); listTest.add("test2"); listTest.add("test3"); mv.addObject("listTest",listTest); // jstl로 호출 mv.addObject("ObjectTest","테스트입니다."); // jstl로 호출 mv.setViewName("mv/testMv"); // 실제 호출될 /WEB-INF/jsp/model/testMv.jsp return mv; }}</string></string> |
** 맨 마지막줄에 </string></string> 은 무시하셔요 **
/WEB-INF/jsp/mv/testMv.jsp
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 |
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>ModelAndView 테스트 페이지입니다.<br>${ObjectTest}<br>${listTest}<br><br><c:foreach items="${listTest}" var="listTest"> ${listTest} <br></c:foreach> |
로 작성하신 후
http://localhost/mv 를 호출하시면 됩니다.
출처: http://jsijsi99.tistory.com/11?category=710810 [삽질대마왕 이대장]
'Franework > Spring boot' 카테고리의 다른 글
| Spring Boot 시작하기 - #8. Srping Boot JSP view 설정하기 (0) | 2018.08.08 |
|---|---|
| Spring Boot 시작하기 7. Mybatis Multi DataSource Spring Boot 시작하기 (0) | 2018.08.08 |
| Spring Boot 시작하기 - #6. MariaDb + Mybatis 연동 (0) | 2018.08.08 |
| Spring Boot 시작하기 - #5_3. Spring Boot 웹 페이지 설정 (0) | 2018.08.08 |
| Spring Boot 시작하기 - #5_2. Eclipse Srping Boot 웹프로젝트 생성 / 가동 (0) | 2018.08.08 |
demo_muliDataSource.zip