728x90
1. 세션 나누기
2. Controller
- DetailController.java
package com.newlecture.web.controller.notice;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
public class DetailController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mv = new ModelAndView("notice.detail");
mv.addObject("data","Hello Spring MVC~");
return mv;
}
}
- ListController.java
package com.newlecture.web.controller.notice;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import com.newlecture.web.entity.Notice;
import com.newlecture.web.service.NoticeService;
public class ListController implements Controller {
//servlet-context.xml에 property생략가능
@Autowired
private NoticeService noticeService;
public void setNoticeService(NoticeService noticeService) {
this.noticeService = noticeService;
System.out.println("Hello");
}
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
/* ModelAndView mv = new ModelAndView("notice/list"); */
/* tiles.xml위해 */
ModelAndView mv = new ModelAndView("notice.list");
List<Notice> list = noticeService.getList(1, "TITLE", ""); /*int page, String field, String query*/
mv.addObject("list",list);
return mv;
}
}
3. tiles.xml
자신이 세션 나눈 경로에 맞게 value에 작성
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
"http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>
<definition name="notice.list" template="/WEB-INF/view/customer/inc/layout.jsp">
<put-attribute name="title" value="공지사항" />
<put-attribute name="header" value="/WEB-INF/view/inc/header.jsp" />
<put-attribute name="visual" value="/WEB-INF/view/customer/inc/visual.jsp" />
<put-attribute name="aside" value="/WEB-INF/view/customer/inc/aside.jsp" />
<put-attribute name="body" value="/WEB-INF/view/customer/notice/list.jsp" />
<put-attribute name="footer" value="/WEB-INF/view/inc/footer.jsp" />
</definition>
<definition name="notice.detail" template="/WEB-INF/view/customer/inc/layout.jsp">
<put-attribute name="title" value="Tiles tutorial homepage" />
<put-attribute name="header" value="/WEB-INF/view/inc/header.jsp" />
<put-attribute name="visual" value="/WEB-INF/view/customer/inc/visual.jsp" />
<put-attribute name="aside" value="/WEB-INF/view/customer/inc/aside.jsp" />
<put-attribute name="body" value="/WEB-INF/view/customer/notice/detail.jsp" />
<put-attribute name="footer" value="/WEB-INF/view/inc/footer.jsp" />
</definition>
</tiles-definitions>
4. 보여줄 페이지 작성.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<!DOCTYPE html>
<html>
<head>
<title>코딩</title>
<meta charset="UTF-8">
<title><tiles:getAsString name="title" /></title>
</head>
<body>
<!-- header 부분 -->
<tiles:insertAttribute name="header" />
<!-- --------------------------- <visual> --------------------------------------- -->
<!-- visual 부분 -->
<tiles:insertAttribute name="visual" />
<!-- --------------------------- <body> --------------------------------------- -->
<div id="body">
<div class="content-container clearfix">
<!-- --------------------------- <aside> --------------------------------------- -->
<!-- aside 부분 -->
<tiles:insertAttribute name="aside" />
<!-- --------------------------- <main> --------------------------------------- -->
<tiles:insertAttribute name="body" />
</div>
</div>
<!-- ------------------- <footer> --------------------------------------- -->
<tiles:insertAttribute name="footer" />
</body>
</html>
1) <%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> 올려주기
2) tiles 태그 올리기 위해선 -> pom.xml
<!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-jsp -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>3.0.8</version>
</dependency>
3) <tiles:getAsString name="..." />
문자열 값을 가져올 수 있다.
728x90
'SPRING' 카테고리의 다른 글
[Spring] 오라클(Oracle) 연동 (Eclipse) (0) | 2022.05.11 |
---|---|
[Spring] tiles ViewResolver 설정하기 (0) | 2022.05.11 |
[Spring] tiles 지시서 작성하기2 (와일드카드이용) (0) | 2022.05.11 |
[Spring] tiles 사용법 (Eclipse) (0) | 2022.05.11 |
[Spring] DataSource 이용 (0) | 2022.05.11 |