728x90
@GetMapping("/basic-objects")
public String basicObjects(HttpSession session){
session.setAttribute("sessionData", "Hello Session");
return "basic/basic-objects";
}
@Component("helloBean")
static class HelloBean{
public String hello(String data){
return "Hello " + data;
}
}
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>식 기본 객체 (Expression Basic Objects)</h1>
<ul>
<li>request = <span th:text="${#request}"></span></li>
<li>response = <span th:text="${#response}"></span></li>
<li>session = <span th:text="${#session}"></span></li>
<li>servletContext = <span th:text="${#servletContext}"></span></li>
<li>locale = <span th:text="${#locale}"></span></li>
</ul>
<h1>편의 객체</h1>
<ul>
<li>Request Parameter = <span th:text="${param.paramData}"></span></li>
<li>session = <span th:text="${session.sessionData}"></span></li>
<li>spring bean = <span th:text="${@helloBean.hello('Spring!')}"></span></
li>
</ul>
</body>
</html>
- 기본 객체 제공
- ${#request}
- ${#response}
- ${#session}
- ${#servletContext}
- ${#locale}
- 편의 객체 제공
- HTTP 요청 파라미터 접근: param
- ${param.paramData}
- HTTP 세션 접근: session
- ${session.sessionData}
- 스프링 빈 접근: @
- ${@helloBean.hello('Spring!')}
- HTTP 요청 파라미터 접근: param
728x90
'스프링 MVC 2편(백엔드 웹 개발 활용 기술)' 카테고리의 다른 글
| Ch01. 타임리프(기본 기능) - URL 링크 (0) | 2022.03.09 |
|---|---|
| Ch01. 타임리프(기본 기능) - 유틸리티 객체와 날짜 (0) | 2022.03.09 |
| Ch01. 타임리프(기본 기능) - 변수(SpringEL) (0) | 2022.03.09 |
| Ch01. 타임리프(기본 기능) - 텍스트(text, utext) (0) | 2022.03.09 |
| Ch01. 타임리프(기본 기능) - 타임리프 소개 (0) | 2022.03.09 |