@@ -40,12 +40,6 @@
-
-
-
-
-
diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/core_tags.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/core_tags.jsp
new file mode 100644
index 0000000000..f5defd101e
--- /dev/null
+++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/core_tags.jsp
@@ -0,0 +1,92 @@
+<%@ page import="java.util.Random" %>
+<%@ page import="java.util.Date" %>
+<%@ page import="java.util.Calendar" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <% int x = Integer.valueOf("a");%>
+
+
+
+ The exception is : ${exceptionThrown}
+ There is an exception: ${exceptionThrown.message}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/core_tags_redirect.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/core_tags_redirect.jsp
new file mode 100644
index 0000000000..e8ab0a60c6
--- /dev/null
+++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/core_tags_redirect.jsp
@@ -0,0 +1,16 @@
+<%@ page import="java.util.Random" %>
+<%@ page import="java.util.Date" %>
+<%@ page import="java.util.Calendar" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/formatting_tags.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/formatting_tags.jsp
new file mode 100644
index 0000000000..1b5cb93cf2
--- /dev/null
+++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/formatting_tags.jsp
@@ -0,0 +1,213 @@
+<%@ page import="java.util.Calendar" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Formatted Number - Currency:
+
+
Formatted Number - Maximum Integer Digits:
+
+
Formatted Number - Maximum Fraction Digits:
+
+
Formatted Number - Grouping:
+
+
Formatted Number - Percent with Maximum Integer Digits:
+
+
Formatted Number - Percent with Minimum Fraction Digits:
+
+
Formatted Number Percent with Minimum Integer Digits:
+
+
Formatted Number - with Pattern:
+
+
Formatted Number - Currency with Internationalization :
+
+
+
+
+
+
+
+
+
+
+
Parsed Number :
+
+
Parsed Number - with Integer Only set to True:
+
+
+
+
+
+
+
+
Formatted Date - with type set to time:
+
+
Formatted Date - with type set to date:
+
+
Formatted Date - with type set to both:
+
+
Formatted Date - with short style for both date and time:
+
+
Formatted Date - with medium style for both date and time:
+
+
Formatted Date - with long style for both date and time:
+
+
Formatted Date - with pattern:
+
+
+
+
+
+
+
+
+
+
Parsed Date:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Time being formatted:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Current Date with Default Time Zone:
+
Change Time Zone to GMT+9
+
+
Date in Changed Zone:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/function_tags.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/function_tags.jsp
new file mode 100644
index 0000000000..d45bfd1d51
--- /dev/null
+++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/function_tags.jsp
@@ -0,0 +1,151 @@
+<%@ page import="java.util.Random" %>
+<%@ page import="java.util.Date" %>
+<%@ page import="java.util.Calendar" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix = "fn"
+ uri = "http://java.sun.com/jsp/jstl/functions" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Found 'first' in string
+
+
+
+
+
+
+
+ Found 'first' string
+
+
+
+ Found 'FIRST' string
+
+
+
+
+
+
+
+ String ends with 'string'
+
+
+
+
+
+
+
With escapeXml() Function:
+
string (1) : ${fn:escapeXml(string1)}
+
string (2) : ${fn:escapeXml(string2)}
+
+
Without escapeXml() Function:
+
string (1) : ${string1}
+
string (2) : ${string2}
+
+
+
+
+
+
Index (1) : ${fn:indexOf(string1, "first")}
+
Index (2) : ${fn:indexOf(string2, "second")}
+
+
+
+
+
+
+
+
Final String : ${string4}
+
+
+
+
+
+
Length of String (1) : ${fn:length(string1)}
+
Length of String (2) : ${fn:length(string2)}
+
+
+
+
+
+
+
Final String : ${string3}
+
+
+
+
+
+
+ String starts with 'This'
+
+
+
+
+
+
+
+
+
Final sub string : ${string3}
+
+
+
+
+
+
+
+
Final sub string : ${string3}
+
+
+
+
+
+
+
+
Final sub string : ${string3}
+
+
+
+
+
+
+
+
Final string : ${string3}
+
+
+
+
+
+
+
+
Final string : ${string3}
+
+
+
+
+
+
+
String (1) Length : ${fn:length(string1)}
+
+
+
String (2) Length : ${fn:length(string2)}
+
Final string : "${string2}"
+
+
+
\ No newline at end of file
diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/sql_tags.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/sql_tags.jsp
new file mode 100644
index 0000000000..df10e41c04
--- /dev/null
+++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/sql_tags.jsp
@@ -0,0 +1,198 @@
+<%@ page import="java.util.Random" %>
+<%@ page import="java.util.Date" %>
+<%@ page import="java.util.Calendar" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ SELECT * from USERS;
+
+
+
+ User ID
+ First Name
+ Last Name
+ Email
+ Registered
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ INSERT INTO USERS(first_name, last_name, email) VALUES ('Grace', 'Adams', 'gracea@domain.com');
+
+
+ SELECT * from USERS;
+
+
+
+ User ID
+ First Name
+ Last Name
+ Email
+ Registered
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DELETE FROM USERS WHERE email = ?
+
+
+
+ SELECT * from USERS;
+
+
+
+ User ID
+ First Name
+ Last Name
+ Email
+ Registered
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ <%
+ Date registered = new Date("2018/03/31");
+ String email = "patrick@baeldung.com";
+ %>
+
+
+ UPDATE Users SET registered = ? WHERE email = ?
+
+
+
+
+ SELECT * from USERS;
+
+
+
+ User ID
+ First Name
+ Last Name
+ Email
+ Registered
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UPDATE Users SET first_name = 'Patrick-Ellis' WHERE email='patrick@baeldung.com'
+
+
+
+ UPDATE Users SET last_name = 'Nelson' WHERE email = 'patrick@baeldung.com'
+
+
+
+ INSERT INTO Users(first_name, last_name, email) VALUES ('Grace', 'Adams', 'gracea@domain.com');
+
+
+
+ SELECT * from USERS;
+
+
+
+ User ID
+ First Name
+ Last Name
+ Email
+ Registered
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-mvc-xml/src/main/webapp/WEB-INF/view/xml_tags.jsp b/spring-mvc-xml/src/main/webapp/WEB-INF/view/xml_tags.jsp
new file mode 100644
index 0000000000..9d93c3c190
--- /dev/null
+++ b/spring-mvc-xml/src/main/webapp/WEB-INF/view/xml_tags.jsp
@@ -0,0 +1,99 @@
+<%@ page import="java.util.Random" %>
+<%@ page import="java.util.Date" %>
+<%@ page import="java.util.Calendar" %>
+<%@ page contentType="text/html;charset=UTF-8" language="java" %>
+<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
+<%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Store Items:
+
+
+ -
+
Steve Madden
+ Sneakers
+ 34
+
+
+ -
+
Pearl Izumi
+ Sneakers
+ 80
+
+
+ -
+
Katy Perry
+ Heels
+ 72
+
+
+
+
+
+
The name of the first item listed in the store is :
+
with price $
+
+
+
+
The second item is :
+
+
+
+ Document has at least one
+ - element.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Item category is Sneakers
+
+
+
+ Item category is Heels
+
+
+
+ Unknown category.
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf/README.md b/spring-thymeleaf/README.md
index 3f8f0ab244..2c37e73ada 100644
--- a/spring-thymeleaf/README.md
+++ b/spring-thymeleaf/README.md
@@ -27,3 +27,6 @@ http://localhost:8082/spring-thymeleaf/addStudent/
http://localhost:8082/spring-thymeleaf/listStudents/
The first URL is the home page of the application. The home page has links to the other two pages.
+
+### Security
+The user/password required is: user1/user1Pass
diff --git a/spring-thymeleaf/pom.xml b/spring-thymeleaf/pom.xml
index 058bd10450..5ce2a4b637 100644
--- a/spring-thymeleaf/pom.xml
+++ b/spring-thymeleaf/pom.xml
@@ -1,210 +1,210 @@
-
- 4.0.0
- com.baeldung
- spring-thymeleaf
- 0.1-SNAPSHOT
- war
-
-
- com.baeldung
- parent-modules
- 1.0.0-SNAPSHOT
-
-
-
- 1.8
-
- 4.3.4.RELEASE
- 4.2.0.RELEASE
- 3.1.0
-
- 3.0.3.RELEASE
- 3.0.0.RELEASE
- 2.1.2
-
- 1.1.0.Final
- 5.3.3.Final
- 5.2.5.Final
-
-
- 2.6
- 1.6.1
- 2.2
-
-
-
-
-
- org.springframework
- spring-context
- ${org.springframework-version}
-
-
-
- commons-logging
- commons-logging
-
-
-
-
- org.springframework
- spring-webmvc
- ${org.springframework-version}
-
-
-
- org.springframework.security
- spring-security-web
- ${springframework-security.version}
-
-
- org.springframework.security
- spring-security-config
- ${springframework-security.version}
-
-
-
- org.thymeleaf
- thymeleaf
- ${org.thymeleaf-version}
-
-
- org.thymeleaf
- thymeleaf-spring4
- ${org.thymeleaf-version}
-
-
-
- nz.net.ultraq.thymeleaf
- thymeleaf-layout-dialect
- ${thymeleaf-layout-dialect.version}
-
-
- org.thymeleaf.extras
- thymeleaf-extras-java8time
- ${org.thymeleaf.extras-version}
-
-
-
- javax.servlet
- javax.servlet-api
- ${javax.servlet-version}
- provided
-
-
-
- javax.validation
- validation-api
- ${javax.validation-version}
-
-
- org.hibernate
- hibernate-validator
- ${hibernate-validator.version}
-
-
-
-
- org.springframework
- spring-test
- ${org.springframework-version}
- test
-
-
-
-
- org.springframework.security
- spring-security-test
- ${springframework-security.version}
- test
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-war-plugin
- ${maven-war-plugin.version}
-
- false
-
-
-
- org.codehaus.cargo
- cargo-maven2-plugin
- ${cargo-maven2-plugin.version}
-
- true
-
- jetty8x
- embedded
-
-
-
-
-
- 8082
-
-
-
-
-
- org.apache.tomcat.maven
- tomcat7-maven-plugin
- ${tomcat7-maven-plugin.version}
-
-
- tomcat-run
-
- exec-war-only
-
- package
-
- /
- false
- webapp.jar
- utf-8
-
-
-
-
-
-
-
-
-
- integration
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- integration-test
-
- test
-
-
-
- **/*LiveTest.java
-
-
- **/*IntegrationTest.java
-
-
-
-
-
-
- json
-
-
-
-
-
-
-
+
+ 4.0.0
+ com.baeldung
+ spring-thymeleaf
+ 0.1-SNAPSHOT
+ war
+
+
+ com.baeldung
+ parent-modules
+ 1.0.0-SNAPSHOT
+
+
+
+ 1.8
+
+ 4.3.4.RELEASE
+ 4.2.0.RELEASE
+ 3.1.0
+
+ 3.0.9.RELEASE
+ 3.0.0.RELEASE
+ 2.1.2
+
+ 1.1.0.Final
+ 5.3.3.Final
+ 5.2.5.Final
+
+
+ 2.6
+ 1.6.1
+ 2.2
+
+
+
+
+
+ org.springframework
+ spring-context
+ ${org.springframework-version}
+
+
+
+ commons-logging
+ commons-logging
+
+
+
+
+ org.springframework
+ spring-webmvc
+ ${org.springframework-version}
+
+
+
+ org.springframework.security
+ spring-security-web
+ ${springframework-security.version}
+
+
+ org.springframework.security
+ spring-security-config
+ ${springframework-security.version}
+
+
+
+ org.thymeleaf
+ thymeleaf
+ ${org.thymeleaf-version}
+
+
+ org.thymeleaf
+ thymeleaf-spring4
+ ${org.thymeleaf-version}
+
+
+
+ nz.net.ultraq.thymeleaf
+ thymeleaf-layout-dialect
+ ${thymeleaf-layout-dialect.version}
+
+
+ org.thymeleaf.extras
+ thymeleaf-extras-java8time
+ ${org.thymeleaf.extras-version}
+
+
+
+ javax.servlet
+ javax.servlet-api
+ ${javax.servlet-version}
+ provided
+
+
+
+ javax.validation
+ validation-api
+ ${javax.validation-version}
+
+
+ org.hibernate
+ hibernate-validator
+ ${hibernate-validator.version}
+
+
+
+
+ org.springframework
+ spring-test
+ ${org.springframework-version}
+ test
+
+
+
+
+ org.springframework.security
+ spring-security-test
+ ${springframework-security.version}
+ test
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-war-plugin
+ ${maven-war-plugin.version}
+
+ false
+
+
+
+ org.codehaus.cargo
+ cargo-maven2-plugin
+ ${cargo-maven2-plugin.version}
+
+ true
+
+ jetty8x
+ embedded
+
+
+
+
+
+ 8082
+
+
+
+
+
+ org.apache.tomcat.maven
+ tomcat7-maven-plugin
+ ${tomcat7-maven-plugin.version}
+
+
+ tomcat-run
+
+ exec-war-only
+
+ package
+
+ /
+ false
+ webapp.jar
+ utf-8
+
+
+
+
+
+
+
+
+
+ integration
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+
+
+ integration-test
+
+ test
+
+
+
+ **/*LiveTest.java
+
+
+ **/*IntegrationTest.java
+
+
+
+
+
+
+ json
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java
index b52e26b93e..2e76877199 100644
--- a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java
+++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/config/WebMVCConfig.java
@@ -77,14 +77,14 @@ public class WebMVCConfig extends WebMvcConfigurerAdapter implements Application
return resolver;
}
- private TemplateEngine templateEngine(ITemplateResolver templateResolver) {
- SpringTemplateEngine engine = new SpringTemplateEngine();
- engine.addDialect(new LayoutDialect(new GroupingStrategy()));
- engine.addDialect(new Java8TimeDialect());
- engine.setTemplateResolver(templateResolver);
- engine.setTemplateEngineMessageSource(messageSource());
- return engine;
- }
+ private TemplateEngine templateEngine(ITemplateResolver templateResolver) {
+ SpringTemplateEngine engine = new SpringTemplateEngine();
+ engine.addDialect(new LayoutDialect(new GroupingStrategy()));
+ engine.addDialect(new Java8TimeDialect());
+ engine.setTemplateResolver(templateResolver);
+ engine.setTemplateEngineMessageSource(messageSource());
+ return engine;
+ }
private ITemplateResolver htmlTemplateResolver() {
SpringResourceTemplateResolver resolver = new SpringResourceTemplateResolver();
@@ -142,7 +142,8 @@ public class WebMVCConfig extends WebMvcConfigurerAdapter implements Application
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
- registry.addResourceHandler("/resources/**").addResourceLocations("/WEB-INF/resources/");
+ registry.addResourceHandler("/resources/**", "/css/**")
+ .addResourceLocations("/WEB-INF/resources/", "/WEB-INF/css/");
}
@Override
diff --git a/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FragmentsController.java b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FragmentsController.java
new file mode 100644
index 0000000000..1dd2caedaf
--- /dev/null
+++ b/spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/FragmentsController.java
@@ -0,0 +1,33 @@
+package com.baeldung.thymeleaf.controller;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.GetMapping;
+
+import com.baeldung.thymeleaf.utils.StudentUtils;
+
+@Controller
+public class FragmentsController {
+
+ @GetMapping("/fragments")
+ public String getHome() {
+ return "fragments.html";
+ }
+
+ @GetMapping("/markup")
+ public String markupPage() {
+ return "markup.html";
+ }
+
+ @GetMapping("/params")
+ public String paramsPage() {
+ return "params.html";
+ }
+
+ @GetMapping("/other")
+ public String otherPage(Model model) {
+ model.addAttribute("data", StudentUtils.buildStudents());
+ return "other.html";
+ }
+
+}
diff --git a/spring-thymeleaf/src/main/resources/messages_en.properties b/spring-thymeleaf/src/main/resources/messages_en.properties
index 33295968e0..d29fd24088 100644
--- a/spring-thymeleaf/src/main/resources/messages_en.properties
+++ b/spring-thymeleaf/src/main/resources/messages_en.properties
@@ -1,9 +1,9 @@
-msg.id=ID
-msg.name=Name
-msg.gender=Gender
-msg.percent=Percentage
-welcome.message=Welcome Student !!!
-msg.AddStudent=Add Student
-msg.ListStudents=List Students
-msg.Home=Home
-
+msg.id=ID
+msg.name=Name
+msg.gender=Gender
+msg.percent=Percentage
+welcome.message=Welcome Student !!!
+msg.AddStudent=Add Student
+msg.ListStudents=List Students
+msg.Home=Home
+
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/css/styles.css b/spring-thymeleaf/src/main/webapp/WEB-INF/css/styles.css
new file mode 100644
index 0000000000..85313345a7
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/css/styles.css
@@ -0,0 +1,13 @@
+body {
+ background-color: lightGray
+}
+
+.dark {
+ background-color: black;
+ color: white;
+}
+
+.light {
+ background-color: #f1f1f1;
+ color: #ccc;
+}
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html
index c5466def25..f3d28d7ef4 100644
--- a/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/addStudent.html
@@ -1,43 +1,43 @@
-
-
-
-Add Student
-
-
- Add Student
-
-
-
+
+
+
+Add Student
+
+
+ Add Student
+
+
+
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments.html
new file mode 100644
index 0000000000..8688c5b370
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments.html
@@ -0,0 +1,12 @@
+
+
+
+Thymeleaf Fragments: home
+
+
+
+
+ Go to the next page to see fragments in action
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/forms.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/forms.html
new file mode 100644
index 0000000000..8e905216b0
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/forms.html
@@ -0,0 +1,12 @@
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/general.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/general.html
new file mode 100644
index 0000000000..d615f42550
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/general.html
@@ -0,0 +1,23 @@
+
+
+
+
+
+
+
+
+
Thymeleaf Fragments sample
+
+ Go to the next page to see fragments in action
+
+ This is another sidebar
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/menus.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/menus.html
new file mode 100644
index 0000000000..e8825e5053
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/menus.html
@@ -0,0 +1,2 @@
+Data received
+No data
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/subtitle.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/subtitle.html
new file mode 100644
index 0000000000..cb8c04dc76
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/subtitle.html
@@ -0,0 +1 @@
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/tables.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/tables.html
new file mode 100644
index 0000000000..c13bf83d98
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/fragments/tables.html
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+ 0
+ Name
+
+
+
+
+
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html
index c7d17a4f66..4e281bb27f 100644
--- a/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/listStudents.html
@@ -1,45 +1,45 @@
-
-
-
-Student List
-
-
-
-
- Student List
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+Student List
+
+
+
+
+ Student List
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/markup.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/markup.html
new file mode 100644
index 0000000000..666c95fc16
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/markup.html
@@ -0,0 +1,13 @@
+
+
+
+
+Thymeleaf Fragments: markup
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/other.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/other.html
new file mode 100644
index 0000000000..00a77ccb09
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/other.html
@@ -0,0 +1,27 @@
+
+
+
+Thymeleaf Fragments: other
+
+
+
+
+
+
+
+
+
+ Id
+ Name
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/main/webapp/WEB-INF/views/params.html b/spring-thymeleaf/src/main/webapp/WEB-INF/views/params.html
new file mode 100644
index 0000000000..a27cb00672
--- /dev/null
+++ b/spring-thymeleaf/src/main/webapp/WEB-INF/views/params.html
@@ -0,0 +1,14 @@
+
+
+
+
+Thymeleaf Fragments: params
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsTest.java b/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsTest.java
new file mode 100644
index 0000000000..93261b02df
--- /dev/null
+++ b/spring-thymeleaf/src/test/java/com/baeldung/thymeleaf/controller/FragmentsTest.java
@@ -0,0 +1,90 @@
+package com.baeldung.thymeleaf.controller;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.mock.web.MockHttpSession;
+import org.springframework.test.web.servlet.MockMvc;
+import org.springframework.test.web.servlet.request.RequestPostProcessor;
+import org.springframework.test.web.servlet.setup.MockMvcBuilders;
+import org.springframework.web.context.WebApplicationContext;
+
+import com.baeldung.thymeleaf.config.InitSecurity;
+import com.baeldung.thymeleaf.config.WebApp;
+import com.baeldung.thymeleaf.config.WebMVCConfig;
+import com.baeldung.thymeleaf.config.WebMVCSecurity;
+
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
+import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.test.context.web.WebAppConfiguration;
+
+import static org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
+import javax.servlet.Filter;
+
+import static org.hamcrest.Matchers.containsString;
+
+@RunWith(SpringJUnit4ClassRunner.class)
+@WebAppConfiguration
+@ContextConfiguration(classes = { WebApp.class, WebMVCConfig.class, WebMVCSecurity.class, InitSecurity.class })
+public class FragmentsTest {
+
+ @Autowired
+ WebApplicationContext wac;
+ @Autowired
+ MockHttpSession session;
+
+ private MockMvc mockMvc;
+
+ @Autowired
+ private Filter springSecurityFilterChain;
+
+ private RequestPostProcessor testUser() {
+ return user("user1").password("user1Pass").roles("USER");
+ }
+
+ @Before
+ public void setup() {
+ mockMvc = MockMvcBuilders.webAppContextSetup(wac).addFilters(springSecurityFilterChain).build();
+ }
+ @Test
+ public void whenAccessingFragmentsRoute_thenViewHasExpectedContent() throws Exception {
+ this.mockMvc
+ .perform(get("/fragments").with(testUser()))
+ .andDo(print())
+ .andExpect(status().isOk())
+ .andExpect(content().string(containsString("Thymeleaf Fragments: home ")));
+ }
+
+ @Test
+ public void whenAccessingParamsRoute_thenViewHasExpectedContent() throws Exception {
+ this.mockMvc
+ .perform(get("/params").with(testUser()))
+ .andDo(print())
+ .andExpect(status().isOk())
+ .andExpect(content().string(containsString("Name ")));
+ }
+
+ @Test
+ public void whenAccessingMarkupRoute_thenViewHasExpectedContent() throws Exception {
+ this.mockMvc
+ .perform(get("/markup").with(testUser()))
+ .andDo(print())
+ .andExpect(status().isOk())
+ .andExpect(content().string(containsString("This is another sidebar
")));
+ }
+ @Test
+ public void whenAccessingOtherRoute_thenViewHasExpectedContent() throws Exception {
+ this.mockMvc
+ .perform(get("/other").with(testUser()))
+ .andDo(print())
+ .andExpect(status().isOk())
+ .andExpect(content().string(containsString("John Smith ")));
+ }
+}
\ No newline at end of file
diff --git a/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/BaeldungReaderMockDelegationTest.java b/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/BaeldungReaderMockDelegationTest.java
index f3cff97d47..3ff0d6416e 100755
--- a/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/BaeldungReaderMockDelegationTest.java
+++ b/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/BaeldungReaderMockDelegationTest.java
@@ -10,7 +10,7 @@ public class BaeldungReaderMockDelegationTest {
EasyMockSupport easyMockSupport = new EasyMockSupport();
@Test
- public void givenBaeldungReader_whenReadAndWrite_thenOperationSupported() {
+ public void givenBaeldungReader_whenReadAndWriteSequencially_thenWorks() {
ArticleReader mockArticleReader = easyMockSupport.createMock(ArticleReader.class);
IArticleWriter mockArticleWriter = easyMockSupport.createMock(IArticleWriter.class);
BaeldungReader baeldungReader = new BaeldungReader(mockArticleReader, mockArticleWriter);
diff --git a/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/BaeldungReaderMockSupportTest.java b/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/BaeldungReaderMockSupportTest.java
index bc3a953d06..3bed89927f 100755
--- a/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/BaeldungReaderMockSupportTest.java
+++ b/testing-modules/mocks/mock-comparisons/src/test/java/com/baeldung/easymock/BaeldungReaderMockSupportTest.java
@@ -17,7 +17,7 @@ public class BaeldungReaderMockSupportTest extends EasyMockSupport {
@Mock IArticleWriter mockArticleWriter;
@Test
- public void givenBaeldungReader_whenReadAndWrite_thenOperationSupported() {
+ public void givenBaeldungReader_whenReadAndWriteSequencially_thenWorks() {
expect(mockArticleReader.next())
.andReturn(null)
.times(2)