JAVA-8291 : Split or move spring-thymeleaf-2 module
This commit is contained in:
-23
@@ -1,23 +0,0 @@
|
||||
package com.baeldung.thymeleaf;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.thymeleaf.templatemode.TemplateMode;
|
||||
import org.thymeleaf.templateresolver.ClassLoaderTemplateResolver;
|
||||
|
||||
@Configuration
|
||||
public class ThymeleafConfig {
|
||||
|
||||
@Bean
|
||||
public ClassLoaderTemplateResolver secondaryTemplateResolver() {
|
||||
ClassLoaderTemplateResolver secondaryTemplateResolver = new ClassLoaderTemplateResolver();
|
||||
secondaryTemplateResolver.setPrefix("templates-2/");
|
||||
secondaryTemplateResolver.setSuffix(".html");
|
||||
secondaryTemplateResolver.setTemplateMode(TemplateMode.HTML);
|
||||
secondaryTemplateResolver.setCharacterEncoding("UTF-8");
|
||||
secondaryTemplateResolver.setOrder(1);
|
||||
secondaryTemplateResolver.setCheckExistence(true);
|
||||
|
||||
return secondaryTemplateResolver;
|
||||
}
|
||||
}
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
package com.baeldung.thymeleaf.mvcdata;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.baeldung.thymeleaf.mvcdata.repository.EmailData;
|
||||
|
||||
@Configuration
|
||||
public class BeanConfig {
|
||||
@Bean
|
||||
public EmailData emailData() {
|
||||
return new EmailData();
|
||||
}
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package com.baeldung.thymeleaf.mvcdata;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.http.HttpSession;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import com.baeldung.thymeleaf.mvcdata.repository.EmailData;
|
||||
|
||||
@Controller
|
||||
public class EmailController {
|
||||
private EmailData emailData = new EmailData();
|
||||
private ServletContext servletContext;
|
||||
|
||||
public EmailController(ServletContext servletContext) {
|
||||
this.servletContext = servletContext;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/email/modelattributes")
|
||||
public String emailModel(Model model) {
|
||||
model.addAttribute("emaildata", emailData);
|
||||
return "mvcdata/email-model-attributes";
|
||||
}
|
||||
|
||||
@ModelAttribute("emailModelAttribute")
|
||||
EmailData emailModelAttribute() {
|
||||
return emailData;
|
||||
}
|
||||
|
||||
@GetMapping(value = "/email/requestparameters")
|
||||
public String emailRequestParameters(
|
||||
@RequestParam(value = "emailsubject") String emailSubject,
|
||||
@RequestParam(value = "emailcontent") String emailContent,
|
||||
@RequestParam(value = "emailaddress") String emailAddress1,
|
||||
@RequestParam(value = "emailaddress") String emailAddress2,
|
||||
@RequestParam(value = "emaillocale") String emailLocale) {
|
||||
return "mvcdata/email-request-parameters";
|
||||
}
|
||||
|
||||
@GetMapping("/email/sessionattributes")
|
||||
public String emailSessionAttributes(HttpSession httpSession) {
|
||||
httpSession.setAttribute("emaildata", emailData);
|
||||
return "mvcdata/email-session-attributes";
|
||||
}
|
||||
|
||||
@GetMapping("/email/servletcontext")
|
||||
public String emailServletContext() {
|
||||
servletContext.setAttribute("emailsubject", emailData.getEmailSubject());
|
||||
servletContext.setAttribute("emailcontent", emailData.getEmailBody());
|
||||
servletContext.setAttribute("emailaddress", emailData.getEmailAddress1());
|
||||
servletContext.setAttribute("emaillocale", emailData.getEmailLocale());
|
||||
return "mvcdata/email-servlet-context";
|
||||
}
|
||||
|
||||
@GetMapping("/email/beandata")
|
||||
public String emailBeanData() {
|
||||
return "mvcdata/email-bean-data";
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
package com.baeldung.thymeleaf.mvcdata.repository;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class EmailData implements Serializable {
|
||||
private String emailSubject;
|
||||
private String emailBody;
|
||||
private String emailLocale;
|
||||
private String emailAddress1;
|
||||
private String emailAddress2;
|
||||
|
||||
public EmailData() {
|
||||
this.emailSubject = "You have received a new message";
|
||||
this.emailBody = "Good morning !";
|
||||
this.emailLocale = "en-US";
|
||||
this.emailAddress1 = "jhon.doe@example.com";
|
||||
this.emailAddress2 = "mark.jakob@example.com";
|
||||
}
|
||||
|
||||
public String getEmailSubject() {
|
||||
return this.emailSubject;
|
||||
}
|
||||
|
||||
public String getEmailBody() {
|
||||
return this.emailBody;
|
||||
}
|
||||
|
||||
public String getEmailLocale() {
|
||||
return this.emailLocale;
|
||||
}
|
||||
|
||||
public String getEmailAddress1() {
|
||||
return this.emailAddress1;
|
||||
}
|
||||
|
||||
public String getEmailAddress2() {
|
||||
return this.emailAddress2;
|
||||
}
|
||||
|
||||
public List<String> getEmailAddresses() {
|
||||
List<String> emailAddresses = new ArrayList<>();
|
||||
emailAddresses.add(getEmailAddress1());
|
||||
emailAddresses.add(getEmailAddress2());
|
||||
return emailAddresses;
|
||||
}
|
||||
}
|
||||
-13
@@ -1,13 +0,0 @@
|
||||
package com.baeldung.thymeleaf.templatedir;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class HelloController {
|
||||
|
||||
@GetMapping("/hello")
|
||||
public String sayHello() {
|
||||
return "hello";
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Enums in Thymeleaf</title>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Hello from 'templates/templates-2'</h2>
|
||||
</body>
|
||||
</html>
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
<!doctype html>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
</head>
|
||||
|
||||
<h2>Enter participant</h2>
|
||||
<form th:action="@{/participants}">
|
||||
|
||||
<input type="text" th:name="participant"/>
|
||||
<select name="country">
|
||||
<option value="de">Germany</option>
|
||||
<option value="nl">Netherlands</option>
|
||||
<option value="pl">Poland</option>
|
||||
<option value="lv">Latvia</option>
|
||||
</select>
|
||||
<button type="submit" th:name="action" th:value="in">check-in</button>
|
||||
<button type="submit" th:name="action" th:value="out">check-out</button>
|
||||
</form>
|
||||
|
||||
<th:block th:if="${id != null}">
|
||||
<h2 >User Details</h2>
|
||||
<p>Details for user [[${id}]] ...</p>
|
||||
</th:block>
|
||||
|
||||
<h2>Users</h2>
|
||||
<th:block th:each="userId: ${userIds}">
|
||||
<p>
|
||||
<a th:href="@{/participants(id=${userId})}"> User [[${userId}]]</a>
|
||||
</p>
|
||||
</th:block>
|
||||
|
||||
</html>
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<body>
|
||||
<h1>Subject</h1>
|
||||
<p th:text="${@emailData.emailSubject}">Subject</p>
|
||||
<h1>Content</h1>
|
||||
<p th:text="${@emailData.emailBody}">Body</p>
|
||||
<h1>Email address</h1>
|
||||
<p th:text="${@emailData.emailAddress1}">Email address</p>
|
||||
<h1>Language</h1>
|
||||
<p th:text="${@emailData.emailLocale}">Language</p>
|
||||
</body>
|
||||
</html>
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<body>
|
||||
<h1>Subject</h1>
|
||||
<p th:text="${emaildata.emailSubject}">Subject</p>
|
||||
<h1>Content</h1>
|
||||
<p th:text="${emaildata.emailBody}"></p>
|
||||
<h1>Email addresses</h1>
|
||||
<p th:each="emailAddress : ${emailModelAttribute.getEmailAddresses()}">
|
||||
<span th:text="${emailAddress}"></span>
|
||||
</p>
|
||||
<h1>Language</h1>
|
||||
<p th:text="${emaildata.emailLocale}"></p>
|
||||
</body>
|
||||
</html>
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<body>
|
||||
<h1>Subject</h1>
|
||||
<p th:text="${param.emailsubject}">Subject</p>
|
||||
<h1>Content</h1>
|
||||
<p th:text="${param.emailcontent}"></p>
|
||||
<h1>Email addresses</h1>
|
||||
<p th:each="emailaddress : ${param.emailaddress}">
|
||||
<span th:text="${emailaddress}"></span>
|
||||
</p>
|
||||
<h1>Email address 1</h1>
|
||||
<p th:text="${param.emailaddress[0]}"></p>
|
||||
<h1>Email address 2</h1>
|
||||
<p th:text="${param.emailaddress[1]}"></p>
|
||||
<h1>Language</h1>
|
||||
<p th:text="${param.emaillocale}"></p>
|
||||
</body>
|
||||
</html>
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<body>
|
||||
<h1>Subject</h1>
|
||||
<p th:text="${#servletContext.getAttribute('emailsubject')}"></p>
|
||||
<h1>Content</h1>
|
||||
<p th:text="${#servletContext.getAttribute('emailcontent')}"></p>
|
||||
<h1>Email address</h1>
|
||||
<p th:text="${#servletContext.getAttribute('emailaddress')}"></p>
|
||||
<h1>Language</h1>
|
||||
<p th:text="${#servletContext.getAttribute('emaillocale')}"></p>
|
||||
</body>
|
||||
</html>
|
||||
-14
@@ -1,14 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:th="http://www.thymeleaf.org">
|
||||
<body>
|
||||
<h1>Subject</h1>
|
||||
<p th:text="${session.emaildata.emailSubject}"></p>
|
||||
<h1>Content</h1>
|
||||
<p th:text="${session.emaildata.emailBody}"></p>
|
||||
<h1>Email address</h1>
|
||||
<p th:text="${session.emaildata.emailAddress1}"></p>
|
||||
<h1>Language</h1>
|
||||
<p th:text="${#session.getAttribute('emaillocale')}"></p>
|
||||
</body>
|
||||
</html>
|
||||
-72
@@ -1,72 +0,0 @@
|
||||
package com.baeldung.thymeleaf.mvcdata;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import com.baeldung.thymeleaf.mvcdata.repository.EmailData;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc(printOnlyOnFailure = false)
|
||||
public class EmailControllerUnitTest {
|
||||
|
||||
EmailData emailData = new EmailData();
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Test
|
||||
public void whenCallModelAttributes_thenReturnEmailData() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/email/modelattributes"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("You have received a new message")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallRequestParameters_thenReturnEmailData() throws Exception {
|
||||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>();
|
||||
params.add("emailsubject", emailData.getEmailSubject());
|
||||
params.add("emailcontent", emailData.getEmailBody());
|
||||
params.add("emailaddress", emailData.getEmailAddress1());
|
||||
params.add("emailaddress", emailData.getEmailAddress2());
|
||||
params.add("emaillocale", emailData.getEmailLocale());
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/email/requestparameters")
|
||||
.params(params))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("en-US")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallSessionAttributes_thenReturnEmailData() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/email/sessionattributes"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("Good morning !")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallServletContext_thenReturnEmailData() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/email/servletcontext"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("jhon.doe@example.com")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCallBeanData_thenReturnEmailData() throws Exception {
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/email/beandata"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string(containsString("jhon.doe@example.com")));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user