Create snippets for BAEL-2574 (#6344)

This commit is contained in:
Andrey Shcherbakov 2019-02-16 23:23:08 +01:00 committed by maibin
parent 91ac058838
commit 033bc8bd5a
7 changed files with 118 additions and 110 deletions

View File

@ -1,66 +1,77 @@
<?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"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-mvc</artifactId>
<name>spring-boot-mvc</name>
<packaging>jar</packaging>
<description>Module For Spring Boot MVC</description>
<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">
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-boot-mvc</artifactId>
<name>spring-boot-mvc</name>
<packaging>jar</packaging>
<description>Module For Spring Boot MVC</description>
<parent>
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<parent>
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencies>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</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 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--JSF -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.3.7</version>
</dependency>
<!-- ROME for RSS -->
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>${rome.version}</version>
</dependency>
<!--Test -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--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>
<!-- ROME for RSS -->
<dependency>
<groupId>com.rometools</groupId>
<artifactId>rome</artifactId>
<version>${rome.version}</version>
</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>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
@ -77,31 +88,27 @@
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
</dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.springbootmvc.SpringBootMvcApplication</mainClass>
<layout>JAR</layout>
</configuration>
</plugin>
</plugins>
</build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.baeldung.springbootmvc.SpringBootMvcApplication</mainClass>
<layout>JAR</layout>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<spring.fox.version>2.9.2</spring.fox.version>
<!-- ROME for RSS -->
<rome.version>1.10.0</rome.version>
<start-class>com.baeldung.springbootmvc.SpringBootMvcApplication</start-class>
</properties>
<properties>
<spring.fox.version>2.9.2</spring.fox.version>
<!-- ROME for RSS -->
<rome.version>1.10.0</rome.version>
<start-class>com.baeldung.springbootmvc.SpringBootMvcApplication</start-class>
</properties>
</project>

View File

@ -9,5 +9,4 @@ public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

View File

@ -23,10 +23,10 @@ public class Controller {
* @return
*/
@RequestMapping("/index")
public ModelAndView index(Map<String, Object> model) {
public ModelAndView thymeleafView(Map<String, Object> model) {
model.put("number", 1234);
model.put("message", "Hello from Spring MVC");
return new ModelAndView("/index");
return new ModelAndView("thymeleaf/index");
}
}

View File

@ -1,3 +1,2 @@
spring.main.allow-bean-definition-overriding=true
spring.mvc.view.prefix=/WEB-INF/jsp/
spring.mvc.view.suffix=.jsp
spring.thymeleaf.view-names=thymeleaf/*

View File

@ -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>

View File

@ -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>

View File

@ -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());
}
}