2021-08-17
This commit is contained in:
@@ -9,5 +9,6 @@ rootProject.name = "spring-boot-examples"
|
|||||||
include(
|
include(
|
||||||
"file-upload", "security", "security-with-jpa", "validation", "testing",
|
"file-upload", "security", "security-with-jpa", "validation", "testing",
|
||||||
"mqtt", "websocket", "restful", "swing", "rest-doc",
|
"mqtt", "websocket", "restful", "swing", "rest-doc",
|
||||||
"cache", "security-with-jwt", "exception", "i18n", "i18n-mustache","mvc"
|
"cache", "security-with-jwt", "exception", "i18n", "i18n-mustache","mvc",
|
||||||
|
"thymeleaf"
|
||||||
)
|
)
|
||||||
|
|||||||
27
thymeleaf/build.gradle.kts
Normal file
27
thymeleaf/build.gradle.kts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
plugins {
|
||||||
|
id("elex-spring-boot")
|
||||||
|
|
||||||
|
id("org.springframework.boot") version "2.5.3"
|
||||||
|
id("io.spring.dependency-management") version "1.0.11.RELEASE"
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-web")
|
||||||
|
implementation("org.springframework.boot:spring-boot-starter-thymeleaf")
|
||||||
|
|
||||||
|
compileOnly("org.projectlombok:lombok")
|
||||||
|
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||||
|
|
||||||
|
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
|
||||||
|
annotationProcessor("org.projectlombok:lombok")
|
||||||
|
|
||||||
|
testImplementation("org.springframework.boot:spring-boot-starter-test")
|
||||||
|
|
||||||
|
}
|
||||||
20
thymeleaf/src/main/java/kr/pe/elex/examples/Application.java
Normal file
20
thymeleaf/src/main/java/kr/pe/elex/examples/Application.java
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
|
@SpringBootApplication
|
||||||
|
public class Application {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
SpringApplication.run(Application.class, args);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class Copyright {
|
||||||
|
private int year = 2021;
|
||||||
|
private String holder = "Elex";
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.util.MultiValueMap;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Controller
|
||||||
|
public class MyController {
|
||||||
|
@Autowired
|
||||||
|
private MyService service;
|
||||||
|
|
||||||
|
@GetMapping({"/", "/persons"})
|
||||||
|
public String index(Model model) {
|
||||||
|
model.addAttribute("user", service.getUser());
|
||||||
|
model.addAttribute("copyright", service.getCopyright());
|
||||||
|
model.addAttribute("personList",service.getPersonList());
|
||||||
|
|
||||||
|
return "main";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
26
thymeleaf/src/main/java/kr/pe/elex/examples/MyService.java
Normal file
26
thymeleaf/src/main/java/kr/pe/elex/examples/MyService.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class MyService {
|
||||||
|
public Person getUser() {
|
||||||
|
return new Person("Charlie", 14);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Person> getPersonList() {
|
||||||
|
return Arrays.asList(
|
||||||
|
new Person("Charlie", 14),
|
||||||
|
new Person("Steve", 34),
|
||||||
|
new Person("Jane", 22));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Copyright getCopyright() {
|
||||||
|
return new Copyright();
|
||||||
|
}
|
||||||
|
}
|
||||||
14
thymeleaf/src/main/java/kr/pe/elex/examples/Person.java
Normal file
14
thymeleaf/src/main/java/kr/pe/elex/examples/Person.java
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
package kr.pe.elex.examples;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class Person {
|
||||||
|
@JsonProperty
|
||||||
|
private String name;
|
||||||
|
@JsonProperty
|
||||||
|
private int age;
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
/*
|
||||||
|
* Spring-boot Examples
|
||||||
|
*
|
||||||
|
* Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
* https://www.elex-project.com/
|
||||||
|
*/
|
||||||
|
|
||||||
|
package kr.pe.elex.examples;
|
||||||
5
thymeleaf/src/main/resources/application.yaml
Normal file
5
thymeleaf/src/main/resources/application.yaml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
spring:
|
||||||
|
application:
|
||||||
|
name: My spring-boot project
|
||||||
|
server:
|
||||||
|
port: 8080
|
||||||
10
thymeleaf/src/main/resources/banner.txt
Normal file
10
thymeleaf/src/main/resources/banner.txt
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
('-. ('-. ) (`-.
|
||||||
|
_( OO) _( OO) ( OO ).
|
||||||
|
(,------.,--. (,------.(_/. \_)-.
|
||||||
|
| .---'| |.-') | .---' \ `.' /
|
||||||
|
| | | | OO ) | | \ /\
|
||||||
|
(| '--. | |`-' |(| '--. \ \ |
|
||||||
|
| .--'(| '---.' | .--' .' \_)
|
||||||
|
| `---.| | | `---. / .'. \
|
||||||
|
`------'`------' `------''--' '--'
|
||||||
|
powered by ELEX
|
||||||
48
thymeleaf/src/main/resources/logback-spring.xml
Normal file
48
thymeleaf/src/main/resources/logback-spring.xml
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
~ Spring-boot Examples
|
||||||
|
~
|
||||||
|
~ Copyright (c) 2021. Elex. All Rights Reserved.
|
||||||
|
~ https://www.elex-project.com/
|
||||||
|
-->
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||||
|
<include resource="org/springframework/boot/logging/logback/console-appender.xml"/>
|
||||||
|
|
||||||
|
<springProperty name="LOG_DIR" source="logging.path"
|
||||||
|
defaultValue="${user.home}/logs"/>
|
||||||
|
<property name="LOG_PATH" value="${LOG_DIR}/stephanie.log"/>
|
||||||
|
|
||||||
|
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>${CONSOLE_LOG_PATTERN}</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<appender name="ROLLING-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
||||||
|
<charset>UTF-8</charset>
|
||||||
|
<pattern>${FILE_LOG_PATTERN}</pattern>
|
||||||
|
</encoder>
|
||||||
|
<file>${LOG_PATH}</file>
|
||||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
|
<fileNamePattern>${LOG_DIR}/sebastian_%d{yyyy-MM-dd}_%i.log.gz</fileNamePattern>
|
||||||
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
||||||
|
<maxFileSize>10MB</maxFileSize>
|
||||||
|
</timeBasedFileNamingAndTriggeringPolicy>
|
||||||
|
<maxHistory>60</maxHistory>
|
||||||
|
</rollingPolicy>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<logger name="kr.pe.elex" level="debug" additivity="false">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="ROLLING-FILE"/>
|
||||||
|
</logger>
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="CONSOLE"/>
|
||||||
|
<appender-ref ref="ROLLING-FILE"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
13
thymeleaf/src/main/resources/templates/fragment.html
Normal file
13
thymeleaf/src/main/resources/templates/fragment.html
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="ko" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head th:fragment="head">
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Fragment</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<footer th:fragment="footer">
|
||||||
|
<p th:object="${copyright}">Copyright © <span th:text="*{year}">2021</span>. <span th:text="*{holder}">ELEX</span>. All Rights Reserved.</p>
|
||||||
|
</footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
17
thymeleaf/src/main/resources/templates/main.html
Normal file
17
thymeleaf/src/main/resources/templates/main.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="ko" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head th:replace="~{fragment :: head}"></head>
|
||||||
|
<body>
|
||||||
|
<p>
|
||||||
|
Hello, <span th:text="${user.name}">User Name</span>.
|
||||||
|
</p>
|
||||||
|
<ul th:each="person : ${personList}">
|
||||||
|
<li>
|
||||||
|
<a th:text="${person.name}"
|
||||||
|
th:attr="data-age=${person.age}"
|
||||||
|
th:href="@{/{name}(name=${person.name})}"></a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<footer th:include="~{fragment :: footer}"></footer>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user