diff --git a/spring-boot-mvc/pom.xml b/spring-boot-mvc/pom.xml index 89fa6bb04d..e17c1d39b9 100644 --- a/spring-boot-mvc/pom.xml +++ b/spring-boot-mvc/pom.xml @@ -1,66 +1,77 @@ - - 4.0.0 - spring-boot-mvc - spring-boot-mvc - jar - Module For Spring Boot MVC + + 4.0.0 + spring-boot-mvc + spring-boot-mvc + jar + Module For Spring Boot MVC - - parent-boot-2 - com.baeldung - 0.0.1-SNAPSHOT - ../parent-boot-2 - + + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 + - + - - org.springframework.boot - spring-boot-starter-web - - - org.apache.tomcat.embed - tomcat-embed-jasper - + + org.springframework.boot + spring-boot-starter-web + + + org.apache.tomcat.embed + tomcat-embed-jasper + + + org.springframework.boot + spring-boot-starter-tomcat + provided + + + org.springframework.boot + spring-boot-starter-thymeleaf + - - - org.glassfish - javax.faces - 2.3.7 - - - - org.springframework.boot - spring-boot-starter-test - test - + + + org.glassfish + javax.faces + 2.3.7 + - - - com.rometools - rome - ${rome.version} - + + + org.springframework.boot + spring-boot-starter-test + test + - - - org.hibernate.validator - hibernate-validator - - - javax.validation - validation-api - - - org.springframework.boot - spring-boot-starter-validation - + + + com.rometools + rome + ${rome.version} + - + + + org.hibernate.validator + hibernate-validator + + + javax.validation + validation-api + + + org.springframework.boot + spring-boot-starter-validation + + + io.springfox springfox-swagger2 @@ -77,31 +88,27 @@ tomcat-embed-jasper provided - - javax.servlet - jstl - - + - - - - org.springframework.boot - spring-boot-maven-plugin - - com.baeldung.springbootmvc.SpringBootMvcApplication - JAR - - - - + + + + org.springframework.boot + spring-boot-maven-plugin + + com.baeldung.springbootmvc.SpringBootMvcApplication + JAR + + + + - - 2.9.2 - - 1.10.0 - com.baeldung.springbootmvc.SpringBootMvcApplication - + + 2.9.2 + + 1.10.0 + com.baeldung.springbootmvc.SpringBootMvcApplication + diff --git a/spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/App.java b/spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/App.java index 2ffbb354c3..c16e784dd2 100644 --- a/spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/App.java +++ b/spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/App.java @@ -9,5 +9,4 @@ public class App { public static void main(String[] args) { SpringApplication.run(App.class, args); } - } diff --git a/spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/Controller.java b/spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/Controller.java index cc838eb6a5..8759f1bcd6 100644 --- a/spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/Controller.java +++ b/spring-boot-mvc/src/main/java/com/baeldung/accessparamsjs/Controller.java @@ -23,10 +23,10 @@ public class Controller { * @return */ @RequestMapping("/index") - public ModelAndView index(Map model) { + public ModelAndView thymeleafView(Map model) { model.put("number", 1234); model.put("message", "Hello from Spring MVC"); - return new ModelAndView("/index"); + return new ModelAndView("thymeleaf/index"); } } diff --git a/spring-boot-mvc/src/main/resources/application.properties b/spring-boot-mvc/src/main/resources/application.properties index 00362e2588..6dab470c84 100644 --- a/spring-boot-mvc/src/main/resources/application.properties +++ b/spring-boot-mvc/src/main/resources/application.properties @@ -1,3 +1,2 @@ spring.main.allow-bean-definition-overriding=true -spring.mvc.view.prefix=/WEB-INF/jsp/ -spring.mvc.view.suffix=.jsp \ No newline at end of file +spring.thymeleaf.view-names=thymeleaf/* \ No newline at end of file diff --git a/spring-boot-mvc/src/main/resources/templates/thymeleaf/index.html b/spring-boot-mvc/src/main/resources/templates/thymeleaf/index.html new file mode 100644 index 0000000000..4939d0ea50 --- /dev/null +++ b/spring-boot-mvc/src/main/resources/templates/thymeleaf/index.html @@ -0,0 +1,29 @@ + + + +Access Spring MVC params + + + + + + + Number= + +
Message= + +

Data from the external JS file (due to loading order)

+
+
+

Asynchronous loading from external JS file (plain JS)

+
+
+

Asynchronous loading from external JS file (jQuery)

+
+
+ + + diff --git a/spring-boot-mvc/src/main/webapp/WEB-INF/jsp/index.jsp b/spring-boot-mvc/src/main/webapp/WEB-INF/jsp/index.jsp deleted file mode 100644 index d9f3966e82..0000000000 --- a/spring-boot-mvc/src/main/webapp/WEB-INF/jsp/index.jsp +++ /dev/null @@ -1,27 +0,0 @@ - -<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> - - -Access Spring MVC params - - - - - - -

Data from the external JS file (due to loading order)

-
-
-

Asynchronous loading from external JS file (plain JS)

-
-
-

Asynchronous loading from external JS file (jQuery)

-
-
- - - - \ No newline at end of file diff --git a/spring-boot-mvc/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java b/spring-boot-mvc/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java index 31f6c89ffe..2dc62a20f6 100644 --- a/spring-boot-mvc/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java +++ b/spring-boot-mvc/src/test/java/com/baeldung/accessparamsjs/ControllerUnitTest.java @@ -20,9 +20,10 @@ public class ControllerUnitTest { private MockMvc mvc; @Test - public void whenRequestIndex_thenStatusOk() throws Exception { + public void whenRequestThymeleaf_thenStatusOk() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/index") .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); } + }