Skip to content

Commit 5147760

Browse files
vkadapadavidmorley
authored andcommitted
Vishwanth: Merged my changes of Thymeleaf POC (Proof of Concept)
1 parent 2228486 commit 5147760

9 files changed

Lines changed: 247 additions & 44 deletions

File tree

‎spring-mvc-java/pom.xml‎

Lines changed: 26 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34
<groupId>org.baeldung</groupId>
45
<artifactId>spring-mvc-java</artifactId>
56
<version>0.1-SNAPSHOT</version>
6-
77
<name>spring-mvc-java</name>
88
<packaging>war</packaging>
9-
109
<dependencies>
11-
1210
<!-- Spring -->
13-
1411
<dependency>
1512
<groupId>org.springframework</groupId>
1613
<artifactId>spring-web</artifactId>
@@ -21,64 +18,53 @@
2118
<artifactId>spring-webmvc</artifactId>
2219
<version>${org.springframework.version}</version>
2320
</dependency>
24-
2521
<!-- web -->
26-
2722
<dependency>
2823
<groupId>javax.servlet</groupId>
2924
<artifactId>javax.servlet-api</artifactId>
3025
<version>3.0.1</version>
3126
<scope>provided</scope>
3227
</dependency>
33-
3428
<dependency>
3529
<groupId>javax.servlet</groupId>
3630
<artifactId>jstl</artifactId>
3731
<version>1.2</version>
3832
<scope>runtime</scope>
3933
</dependency>
40-
4134
<!-- AOP -->
4235
<dependency>
4336
<groupId>org.springframework</groupId>
4437
<artifactId>spring-aop</artifactId>
4538
<version>${org.springframework.version}</version>
4639
</dependency>
47-
4840
<dependency>
4941
<groupId>org.aspectj</groupId>
5042
<artifactId>aspectjrt</artifactId>
5143
<version>${aspectj.version}</version>
5244
</dependency>
53-
5445
<dependency>
5546
<groupId>org.aspectj</groupId>
5647
<artifactId>aspectjweaver</artifactId>
5748
<version>${aspectj.version}</version>
5849
</dependency>
59-
6050
<!-- logging -->
6151
<dependency>
6252
<groupId>org.slf4j</groupId>
6353
<artifactId>slf4j-api</artifactId>
6454
<version>${org.slf4j.version}</version>
6555
</dependency>
66-
6756
<dependency>
6857
<groupId>org.slf4j</groupId>
6958
<artifactId>slf4j-log4j12</artifactId>
7059
<version>${org.slf4j.version}</version>
7160
</dependency>
72-
7361
<!-- test scoped -->
74-
7562
<dependency>
7663
<groupId>junit</groupId>
7764
<artifactId>junit-dep</artifactId>
7865
<version>${junit.version}</version>
7966
<scope>test</scope>
8067
</dependency>
81-
8268
<dependency>
8369
<groupId>org.hamcrest</groupId>
8470
<artifactId>hamcrest-core</artifactId>
@@ -91,23 +77,30 @@
9177
<version>${org.hamcrest.version}</version>
9278
<scope>test</scope>
9379
</dependency>
94-
9580
<dependency>
9681
<groupId>org.mockito</groupId>
9782
<artifactId>mockito-core</artifactId>
9883
<version>${mockito.version}</version>
9984
<scope>test</scope>
10085
</dependency>
101-
10286
<dependency>
10387
<groupId>org.springframework</groupId>
10488
<artifactId>spring-test</artifactId>
10589
<version>${org.springframework.version}</version>
10690
<scope>test</scope>
10791
</dependency>
108-
92+
<!-- Thymeleaf -->
93+
<dependency>
94+
<groupId>org.thymeleaf</groupId>
95+
<artifactId>thymeleaf-spring4</artifactId>
96+
<version>${thymeleaf.version}</version>
97+
</dependency>
98+
<dependency>
99+
<groupId>org.thymeleaf</groupId>
100+
<artifactId>thymeleaf</artifactId>
101+
<version>${thymeleaf.version}</version>
102+
</dependency>
109103
</dependencies>
110-
111104
<build>
112105
<finalName>spring-mvc-java</finalName>
113106
<resources>
@@ -116,9 +109,7 @@
116109
<filtering>true</filtering>
117110
</resource>
118111
</resources>
119-
120112
<plugins>
121-
122113
<plugin>
123114
<groupId>org.apache.maven.plugins</groupId>
124115
<artifactId>maven-compiler-plugin</artifactId>
@@ -128,7 +119,10 @@
128119
<target>1.8</target>
129120
</configuration>
130121
</plugin>
131-
122+
<plugin>
123+
<artifactId>maven-resources-plugin</artifactId>
124+
<version>2.7</version>
125+
</plugin>
132126
<plugin>
133127
<groupId>org.apache.maven.plugins</groupId>
134128
<artifactId>maven-war-plugin</artifactId>
@@ -137,7 +131,6 @@
137131
<failOnMissingWebXml>false</failOnMissingWebXml>
138132
</configuration>
139133
</plugin>
140-
141134
<plugin>
142135
<groupId>org.apache.maven.plugins</groupId>
143136
<artifactId>maven-surefire-plugin</artifactId>
@@ -151,7 +144,6 @@
151144
</systemPropertyVariables>
152145
</configuration>
153146
</plugin>
154-
155147
<plugin>
156148
<groupId>org.codehaus.cargo</groupId>
157149
<artifactId>cargo-maven2-plugin</artifactId>
@@ -172,50 +164,46 @@
172164
</configuration>
173165
</configuration>
174166
</plugin>
175-
167+
<plugin>
168+
<groupId>org.apache.tomcat.maven</groupId>
169+
<artifactId>tomcat7-maven-plugin</artifactId>
170+
<version>2.2</version>
171+
<configuration>
172+
<path>/</path>
173+
</configuration>
174+
</plugin>
176175
</plugins>
177-
178176
</build>
179-
180177
<properties>
181178
<!-- Spring -->
182179
<org.springframework.version>4.2.2.RELEASE</org.springframework.version>
183180
<org.springframework.security.version>4.0.2.RELEASE</org.springframework.security.version>
184-
181+
<thymeleaf.version>2.1.4.RELEASE</thymeleaf.version>
185182
<!-- persistence -->
186183
<hibernate.version>4.3.11.Final</hibernate.version>
187184
<mysql-connector-java.version>5.1.36</mysql-connector-java.version>
188-
189185
<!-- logging -->
190186
<org.slf4j.version>1.7.12</org.slf4j.version>
191187
<logback.version>1.1.3</logback.version>
192-
193188
<!-- various -->
194189
<hibernate-validator.version>5.2.1.Final</hibernate-validator.version>
195-
196190
<!-- util -->
197191
<guava.version>18.0</guava.version>
198192
<commons-lang3.version>3.4</commons-lang3.version>
199-
200193
<!-- testing -->
201194
<org.hamcrest.version>1.3</org.hamcrest.version>
202195
<junit.version>4.11</junit.version>
203196
<mockito.version>1.10.19</mockito.version>
204-
205197
<httpcore.version>4.4.1</httpcore.version>
206198
<httpclient.version>4.5</httpclient.version>
207-
208199
<rest-assured.version>2.4.1</rest-assured.version>
209-
210200
<!-- maven plugins -->
211201
<maven-compiler-plugin.version>3.3</maven-compiler-plugin.version>
212202
<maven-war-plugin.version>2.6</maven-war-plugin.version>
213203
<maven-surefire-plugin.version>2.18.1</maven-surefire-plugin.version>
214204
<maven-resources-plugin.version>2.7</maven-resources-plugin.version>
215205
<cargo-maven2-plugin.version>1.4.15</cargo-maven2-plugin.version>
216-
217206
<!-- AspectJ -->
218207
<aspectj.version>1.8.7</aspectj.version>
219208
</properties>
220-
221209
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package org.baeldung.controller;
2+
3+
import org.baeldung.model.UserDetails;
4+
import org.springframework.stereotype.Controller;
5+
import org.springframework.ui.Model;
6+
import org.springframework.web.bind.annotation.ModelAttribute;
7+
import org.springframework.web.bind.annotation.RequestMapping;
8+
import org.springframework.web.bind.annotation.RequestMethod;
9+
10+
@Controller
11+
@RequestMapping("/")
12+
public class UserController {
13+
14+
@RequestMapping(value = "/", method = RequestMethod.GET)
15+
public String showForm(final Model model) {
16+
final UserDetails user = new UserDetails();
17+
user.setFirstname("John");
18+
user.setLastname("Roy");
19+
user.setEmailId("John.Roy@gmail.com");
20+
model.addAttribute("user", user);
21+
return "index";
22+
}
23+
24+
@RequestMapping(value = "/processForm", method = RequestMethod.POST)
25+
public String processForm(@ModelAttribute(value = "user") final UserDetails user, final Model model) {
26+
// Insert userDetails into DB
27+
model.addAttribute("name", user.getFirstname() + " " + user.getLastname());
28+
return "hello";
29+
}
30+
31+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package org.baeldung.dialect;
2+
3+
import java.util.HashSet;
4+
import java.util.Set;
5+
6+
import org.baeldung.processor.NameProcessor;
7+
import org.thymeleaf.dialect.AbstractDialect;
8+
import org.thymeleaf.processor.IProcessor;
9+
10+
public class CustomDialect extends AbstractDialect {
11+
12+
@Override
13+
public String getPrefix() {
14+
return "custom";
15+
}
16+
17+
@Override
18+
public Set<IProcessor> getProcessors() {
19+
final Set<IProcessor> processors = new HashSet<IProcessor>();
20+
processors.add(new NameProcessor());
21+
return processors;
22+
}
23+
24+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package org.baeldung.model;
2+
3+
public class UserDetails {
4+
private String firstname;
5+
private String lastname;
6+
private String emailId;
7+
8+
public String getFirstname() {
9+
return firstname;
10+
}
11+
12+
public void setFirstname(final String firstname) {
13+
this.firstname = firstname;
14+
}
15+
16+
public String getLastname() {
17+
return lastname;
18+
}
19+
20+
public void setLastname(final String lastname) {
21+
this.lastname = lastname;
22+
}
23+
24+
public String getEmailId() {
25+
return emailId;
26+
}
27+
28+
public void setEmailId(final String emailId) {
29+
this.emailId = emailId;
30+
}
31+
32+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package org.baeldung.processor;
2+
3+
import org.thymeleaf.Arguments;
4+
import org.thymeleaf.dom.Element;
5+
import org.thymeleaf.processor.attr.AbstractTextChildModifierAttrProcessor;
6+
7+
public class NameProcessor extends AbstractTextChildModifierAttrProcessor {
8+
9+
public NameProcessor() {
10+
super("name");
11+
}
12+
13+
@Override
14+
protected String getText(final Arguments arguements, final Element elements, final String attributeName) {
15+
return "Hello, " + elements.getAttributeValue(attributeName) + "!";
16+
}
17+
18+
@Override
19+
public int getPrecedence() {
20+
return 1000;
21+
}
22+
23+
}

0 commit comments

Comments
 (0)