노출되는 이미지가 불편하시겠지만 양해를 구합니다. 노출, 클릭등에 관한 자료로 활용 중입니다.


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



참조

http://coderscampus.com/ep01-spring-boot-rocks/

https://hellokoding.com/spring-boot-hello-world-example-with-thymeleaf/

블로그 이미지

StartGuide

I want to share the basic to programming of each category and how to solve the error. This basic instruction can be extended further. And I have been worked in southeast Asia more than 3 years. And I want to have the chance to work another country.

,