Create snippets for BAEL-2574 (#6344)
This commit is contained in:
parent
91ac058838
commit
033bc8bd5a
|
@ -1,66 +1,77 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
<modelVersion>4.0.0</modelVersion>
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<artifactId>spring-boot-mvc</artifactId>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<name>spring-boot-mvc</name>
|
<artifactId>spring-boot-mvc</artifactId>
|
||||||
<packaging>jar</packaging>
|
<name>spring-boot-mvc</name>
|
||||||
<description>Module For Spring Boot MVC</description>
|
<packaging>jar</packaging>
|
||||||
|
<description>Module For Spring Boot MVC</description>
|
||||||
|
|
||||||
<parent>
|
<parent>
|
||||||
<artifactId>parent-boot-2</artifactId>
|
<artifactId>parent-boot-2</artifactId>
|
||||||
<groupId>com.baeldung</groupId>
|
<groupId>com.baeldung</groupId>
|
||||||
<version>0.0.1-SNAPSHOT</version>
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
<relativePath>../parent-boot-2</relativePath>
|
<relativePath>../parent-boot-2</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-web</artifactId>
|
<artifactId>spring-boot-starter-web</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.tomcat.embed</groupId>
|
<groupId>org.apache.tomcat.embed</groupId>
|
||||||
<artifactId>tomcat-embed-jasper</artifactId>
|
<artifactId>tomcat-embed-jasper</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-tomcat</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!--JSF -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.glassfish</groupId>
|
|
||||||
<artifactId>javax.faces</artifactId>
|
|
||||||
<version>2.3.7</version>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--Test -->
|
<!--JSF -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.glassfish</groupId>
|
||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>javax.faces</artifactId>
|
||||||
<scope>test</scope>
|
<version>2.3.7</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- ROME for RSS -->
|
<!--Test -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rometools</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>rome</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<version>${rome.version}</version>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!--Validation -->
|
<!-- ROME for RSS -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate.validator</groupId>
|
<groupId>com.rometools</groupId>
|
||||||
<artifactId>hibernate-validator</artifactId>
|
<artifactId>rome</artifactId>
|
||||||
</dependency>
|
<version>${rome.version}</version>
|
||||||
<dependency>
|
</dependency>
|
||||||
<groupId>javax.validation</groupId>
|
|
||||||
<artifactId>validation-api</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.springframework.boot</groupId>
|
|
||||||
<artifactId>spring-boot-starter-validation</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!-- Spring Fox 2 -->
|
<!--Validation -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate.validator</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.validation</groupId>
|
||||||
|
<artifactId>validation-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-validation</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<!-- Spring Fox 2 -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.springfox</groupId>
|
<groupId>io.springfox</groupId>
|
||||||
<artifactId>springfox-swagger2</artifactId>
|
<artifactId>springfox-swagger2</artifactId>
|
||||||
|
@ -77,31 +88,27 @@
|
||||||
<artifactId>tomcat-embed-jasper</artifactId>
|
<artifactId>tomcat-embed-jasper</artifactId>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>javax.servlet</groupId>
|
|
||||||
<artifactId>jstl</artifactId>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<mainClass>com.baeldung.springbootmvc.SpringBootMvcApplication</mainClass>
|
<mainClass>com.baeldung.springbootmvc.SpringBootMvcApplication</mainClass>
|
||||||
<layout>JAR</layout>
|
<layout>JAR</layout>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<spring.fox.version>2.9.2</spring.fox.version>
|
<spring.fox.version>2.9.2</spring.fox.version>
|
||||||
<!-- ROME for RSS -->
|
<!-- ROME for RSS -->
|
||||||
<rome.version>1.10.0</rome.version>
|
<rome.version>1.10.0</rome.version>
|
||||||
<start-class>com.baeldung.springbootmvc.SpringBootMvcApplication</start-class>
|
<start-class>com.baeldung.springbootmvc.SpringBootMvcApplication</start-class>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -9,5 +9,4 @@ public class App {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(App.class, args);
|
SpringApplication.run(App.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,10 +23,10 @@ public class Controller {
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@RequestMapping("/index")
|
@RequestMapping("/index")
|
||||||
public ModelAndView index(Map<String, Object> model) {
|
public ModelAndView thymeleafView(Map<String, Object> model) {
|
||||||
model.put("number", 1234);
|
model.put("number", 1234);
|
||||||
model.put("message", "Hello from Spring MVC");
|
model.put("message", "Hello from Spring MVC");
|
||||||
return new ModelAndView("/index");
|
return new ModelAndView("thymeleaf/index");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
spring.main.allow-bean-definition-overriding=true
|
spring.main.allow-bean-definition-overriding=true
|
||||||
spring.mvc.view.prefix=/WEB-INF/jsp/
|
spring.thymeleaf.view-names=thymeleaf/*
|
||||||
spring.mvc.view.suffix=.jsp
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<title>Access Spring MVC params</title>
|
||||||
|
<script src="/js/jquery.js"></script>
|
||||||
|
<script src="/js/script-async.js"></script>
|
||||||
|
<script src="/js/script-async-jquery.js"></script>
|
||||||
|
<script>
|
||||||
|
var number = [[${number}]];
|
||||||
|
var message = "[[${message}]]";
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
Number=
|
||||||
|
<span th:text="${number}" th:remove="tag"></span>
|
||||||
|
<br /> Message=
|
||||||
|
<span th:text="${message}" th:remove="tag"></span>
|
||||||
|
<h2>Data from the external JS file (due to loading order)</h2>
|
||||||
|
<div id="number-ext"></div>
|
||||||
|
<div id="message-ext"></div>
|
||||||
|
<h2>Asynchronous loading from external JS file (plain JS)</h2>
|
||||||
|
<div id="number-async"></div>
|
||||||
|
<div id="message-async"></div>
|
||||||
|
<h2>Asynchronous loading from external JS file (jQuery)</h2>
|
||||||
|
<div id="number-async-jquery"></div>
|
||||||
|
<div id="message-async-jquery"></div>
|
||||||
|
</body>
|
||||||
|
<script src="/js/script.js"></script>
|
||||||
|
</html>
|
|
@ -1,27 +0,0 @@
|
||||||
<!DOCTYPE html>
|
|
||||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<title>Access Spring MVC params</title>
|
|
||||||
<script src="/js/jquery.js"></script>
|
|
||||||
<script src="/js/script-async.js"></script>
|
|
||||||
<script src="/js/script-async-jquery.js"></script>
|
|
||||||
<script>
|
|
||||||
var number = <c:out value="${number}"></c:out>;
|
|
||||||
var message = "<c:out value="${message}"></c:out>";
|
|
||||||
</script>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h2>Data from the external JS file (due to loading order)</h2>
|
|
||||||
<div id="number-ext"></div>
|
|
||||||
<div id="message-ext"></div>
|
|
||||||
<h2>Asynchronous loading from external JS file (plain JS)</h2>
|
|
||||||
<div id="number-async"></div>
|
|
||||||
<div id="message-async"></div>
|
|
||||||
<h2>Asynchronous loading from external JS file (jQuery)</h2>
|
|
||||||
<div id="number-async-jquery"></div>
|
|
||||||
<div id="message-async-jquery"></div>
|
|
||||||
|
|
||||||
</body>
|
|
||||||
<script src="/js/script.js"></script>
|
|
||||||
</html>
|
|
|
@ -20,9 +20,10 @@ public class ControllerUnitTest {
|
||||||
private MockMvc mvc;
|
private MockMvc mvc;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRequestIndex_thenStatusOk() throws Exception {
|
public void whenRequestThymeleaf_thenStatusOk() throws Exception {
|
||||||
mvc.perform(MockMvcRequestBuilders.get("/index")
|
mvc.perform(MockMvcRequestBuilders.get("/index")
|
||||||
.accept(MediaType.APPLICATION_JSON))
|
.accept(MediaType.APPLICATION_JSON))
|
||||||
.andExpect(status().isOk());
|
.andExpect(status().isOk());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue