Skip to content

Commit 033bc8b

Browse files
veontomomaibin
authored andcommitted
Create snippets for BAEL-2574 (eugenp#6344)
1 parent 91ac058 commit 033bc8b

7 files changed

Lines changed: 118 additions & 110 deletions

File tree

‎spring-boot-mvc/pom.xml‎

Lines changed: 84 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,77 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4-
<modelVersion>4.0.0</modelVersion>
5-
<artifactId>spring-boot-mvc</artifactId>
6-
<name>spring-boot-mvc</name>
7-
<packaging>jar</packaging>
8-
<description>Module For Spring Boot MVC</description>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
<artifactId>spring-boot-mvc</artifactId>
7+
<name>spring-boot-mvc</name>
8+
<packaging>jar</packaging>
9+
<description>Module For Spring Boot MVC</description>
910

10-
<parent>
11-
<artifactId>parent-boot-2</artifactId>
12-
<groupId>com.baeldung</groupId>
13-
<version>0.0.1-SNAPSHOT</version>
14-
<relativePath>../parent-boot-2</relativePath>
15-
</parent>
11+
<parent>
12+
<artifactId>parent-boot-2</artifactId>
13+
<groupId>com.baeldung</groupId>
14+
<version>0.0.1-SNAPSHOT</version>
15+
<relativePath>../parent-boot-2</relativePath>
16+
</parent>
1617

17-
<dependencies>
18+
<dependencies>
19+
20+
<dependency>
21+
<groupId>org.springframework.boot</groupId>
22+
<artifactId>spring-boot-starter-web</artifactId>
23+
</dependency>
24+
<dependency>
25+
<groupId>org.apache.tomcat.embed</groupId>
26+
<artifactId>tomcat-embed-jasper</artifactId>
27+
</dependency>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-tomcat</artifactId>
31+
<scope>provided</scope>
32+
</dependency>
33+
<dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
36+
</dependency>
1837

19-
<dependency>
20-
<groupId>org.springframework.boot</groupId>
21-
<artifactId>spring-boot-starter-web</artifactId>
22-
</dependency>
23-
<dependency>
24-
<groupId>org.apache.tomcat.embed</groupId>
25-
<artifactId>tomcat-embed-jasper</artifactId>
26-
</dependency>
2738

28-
<!--JSF -->
29-
<dependency>
30-
<groupId>org.glassfish</groupId>
31-
<artifactId>javax.faces</artifactId>
32-
<version>2.3.7</version>
33-
</dependency>
39+
<!--JSF -->
40+
<dependency>
41+
<groupId>org.glassfish</groupId>
42+
<artifactId>javax.faces</artifactId>
43+
<version>2.3.7</version>
44+
</dependency>
3445

35-
<!--Test -->
36-
<dependency>
37-
<groupId>org.springframework.boot</groupId>
38-
<artifactId>spring-boot-starter-test</artifactId>
39-
<scope>test</scope>
40-
</dependency>
46+
<!--Test -->
47+
<dependency>
48+
<groupId>org.springframework.boot</groupId>
49+
<artifactId>spring-boot-starter-test</artifactId>
50+
<scope>test</scope>
51+
</dependency>
4152

42-
<!-- ROME for RSS -->
43-
<dependency>
44-
<groupId>com.rometools</groupId>
45-
<artifactId>rome</artifactId>
46-
<version>${rome.version}</version>
47-
</dependency>
53+
<!-- ROME for RSS -->
54+
<dependency>
55+
<groupId>com.rometools</groupId>
56+
<artifactId>rome</artifactId>
57+
<version>${rome.version}</version>
58+
</dependency>
4859

49-
<!--Validation -->
50-
<dependency>
51-
<groupId>org.hibernate.validator</groupId>
52-
<artifactId>hibernate-validator</artifactId>
53-
</dependency>
54-
<dependency>
55-
<groupId>javax.validation</groupId>
56-
<artifactId>validation-api</artifactId>
57-
</dependency>
58-
<dependency>
59-
<groupId>org.springframework.boot</groupId>
60-
<artifactId>spring-boot-starter-validation</artifactId>
61-
</dependency>
60+
<!--Validation -->
61+
<dependency>
62+
<groupId>org.hibernate.validator</groupId>
63+
<artifactId>hibernate-validator</artifactId>
64+
</dependency>
65+
<dependency>
66+
<groupId>javax.validation</groupId>
67+
<artifactId>validation-api</artifactId>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.springframework.boot</groupId>
71+
<artifactId>spring-boot-starter-validation</artifactId>
72+
</dependency>
6273

63-
<!-- Spring Fox 2 -->
74+
<!-- Spring Fox 2 -->
6475
<dependency>
6576
<groupId>io.springfox</groupId>
6677
<artifactId>springfox-swagger2</artifactId>
@@ -77,31 +88,27 @@
7788
<artifactId>tomcat-embed-jasper</artifactId>
7889
<scope>provided</scope>
7990
</dependency>
80-
<dependency>
81-
<groupId>javax.servlet</groupId>
82-
<artifactId>jstl</artifactId>
83-
</dependency>
8491

85-
</dependencies>
92+
</dependencies>
8693

87-
<build>
88-
<plugins>
89-
<plugin>
90-
<groupId>org.springframework.boot</groupId>
91-
<artifactId>spring-boot-maven-plugin</artifactId>
92-
<configuration>
93-
<mainClass>com.baeldung.springbootmvc.SpringBootMvcApplication</mainClass>
94-
<layout>JAR</layout>
95-
</configuration>
96-
</plugin>
97-
</plugins>
98-
</build>
94+
<build>
95+
<plugins>
96+
<plugin>
97+
<groupId>org.springframework.boot</groupId>
98+
<artifactId>spring-boot-maven-plugin</artifactId>
99+
<configuration>
100+
<mainClass>com.baeldung.springbootmvc.SpringBootMvcApplication</mainClass>
101+
<layout>JAR</layout>
102+
</configuration>
103+
</plugin>
104+
</plugins>
105+
</build>
99106

100-
<properties>
101-
<spring.fox.version>2.9.2</spring.fox.version>
102-
<!-- ROME for RSS -->
103-
<rome.version>1.10.0</rome.version>
104-
<start-class>com.baeldung.springbootmvc.SpringBootMvcApplication</start-class>
105-
</properties>
107+
<properties>
108+
<spring.fox.version>2.9.2</spring.fox.version>
109+
<!-- ROME for RSS -->
110+
<rome.version>1.10.0</rome.version>
111+
<start-class>com.baeldung.springbootmvc.SpringBootMvcApplication</start-class>
112+
</properties>
106113

107114
</project>

‎spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/App.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ public class App {
99
public static void main(String[] args) {
1010
SpringApplication.run(App.class, args);
1111
}
12-
1312
}

‎spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/Controller.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@ public class Controller {
2323
* @return
2424
*/
2525
@RequestMapping("/index")
26-
public ModelAndView index(Map<String, Object> model) {
26+
public ModelAndView thymeleafView(Map<String, Object> model) {
2727
model.put("number", 1234);
2828
model.put("message", "Hello from Spring MVC");
29-
return new ModelAndView("/index");
29+
return new ModelAndView("thymeleaf/index");
3030
}
3131

3232
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
spring.main.allow-bean-definition-overriding=true
2-
spring.mvc.view.prefix=/WEB-INF/jsp/
3-
spring.mvc.view.suffix=.jsp
2+
spring.thymeleaf.view-names=thymeleaf/*
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!DOCTYPE html>
2+
<html xmlns:th="http://www.thymeleaf.org">
3+
<head>
4+
<title>Access Spring MVC params</title>
5+
<script src="/js/jquery.js"></script>
6+
<script src="/js/script-async.js"></script>
7+
<script src="/js/script-async-jquery.js"></script>
8+
<script>
9+
var number = [[${number}]];
10+
var message = "[[${message}]]";
11+
</script>
12+
</head>
13+
<body>
14+
Number=
15+
<span th:text="${number}" th:remove="tag"></span>
16+
<br /> Message=
17+
<span th:text="${message}" th:remove="tag"></span>
18+
<h2>Data from the external JS file (due to loading order)</h2>
19+
<div id="number-ext"></div>
20+
<div id="message-ext"></div>
21+
<h2>Asynchronous loading from external JS file (plain JS)</h2>
22+
<div id="number-async"></div>
23+
<div id="message-async"></div>
24+
<h2>Asynchronous loading from external JS file (jQuery)</h2>
25+
<div id="number-async-jquery"></div>
26+
<div id="message-async-jquery"></div>
27+
</body>
28+
<script src="/js/script.js"></script>
29+
</html>

‎spring-boot-mvc/src/main/webapp/WEB-INF/jsp/index.jsp‎

Lines changed: 0 additions & 27 deletions
This file was deleted.

‎spring-boot-mvc/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public class ControllerUnitTest {
2020
private MockMvc mvc;
2121

2222
@Test
23-
public void whenRequestIndex_thenStatusOk() throws Exception {
23+
public void whenRequestThymeleaf_thenStatusOk() throws Exception {
2424
mvc.perform(MockMvcRequestBuilders.get("/index")
2525
.accept(MediaType.APPLICATION_JSON))
2626
.andExpect(status().isOk());
2727
}
28+
2829
}

0 commit comments

Comments
 (0)