노출되는 이미지가 불편하시겠지만 양해를 구합니다. 노출, 클릭등에 관한 자료로 활용 중입니다.
Spring Boot , Thymeleaf 설정
1. 프로젝트 생성
- download , project import
* import후에 에러가 발생한다면, Maven Project 버젼을 내려서 시도.
2. 모듈 작성
- src/main/java
-- com.example.HelloController.java
package com.example;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
/**
*
* Controller maps HTTP Requests with view.
*
*/
@Controller
public class HelloController {
@RequestMapping("/hello")
public String hello(Model model,
@RequestParam(value="name",required=false, defaultValue="World") String name) {
model.addAttribute("name", name);
return "hello";
}
}
- src/main/resources
-- templates/hello.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8" />
<title>Hello Thymeleaf!</title>
</head>
<body>
<p th:text="'Hello '+ ${name} +'!'" />
</body>
</html>
* thymeleaf
-- extends SpringBootServletInitializer , configure()
package com.example;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
@SpringBootApplication
public class ThymeleafappApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(ThymeleafappApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(ThymeleafappApplication.class);
}
}
-- Run As -> Spring Boot App
참조
https://hellokoding.com/spring-boot-hello-world-example-with-thymeleaf/
'Web Tech. > Spring Framework' 카테고리의 다른 글
vaddin 뉴스 - Vaadin Board for Java is now available (0) | 2017.07.06 |
---|---|
Tomcat에 SSL(HTTPS)추가 하기 (0) | 2017.07.05 |
2016년 Java 개발 Tool 및 기술 사용 분석/동향 (0) | 2017.03.20 |
Vaadin Appication 만들기 (0) | 2017.03.08 |
XSS ( Cross Site Scripting ) 제거 하기 ( 필터링 ) (0) | 2017.03.07 |