Last active
March 26, 2024 14:48
-
-
Save christianjjc/44aa2db3d4948046094fdd1cd83d8f7d to your computer and use it in GitHub Desktop.
Spring-MVC-Thymeleaf Basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns="http://www.springframework.org/schema/beans" | |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:context="http://www.springframework.org/schema/context" | |
xmlns:mvc="http://www.springframework.org/schema/mvc" | |
xsi:schemaLocation="http://www.springframework.org/schema/beans | |
http://www.springframework.org/schema/beans/spring-beans.xsd | |
http://www.springframework.org/schema/context | |
http://www.springframework.org/schema/context/spring-context.xsd | |
http://www.springframework.org/schema/mvc | |
http://www.springframework.org/schema/mvc/spring-mvc.xsd"> | |
<mvc:annotation-driven /> | |
<context:component-scan base-package="pe.cjjc.projects"/> | |
<!-- Bean para la resolución de paginas de tipo Thymeleaf --> | |
<bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"> | |
<property name="prefix" value="/WEB-INF/views/" /> | |
<property name="suffix" value=".html" /> | |
<property name="templateMode" value="HTML5" /> | |
</bean> | |
<bean id="templateEngine" class="org.thymeleaf.spring5.SpringTemplateEngine"> | |
<property name="templateResolver" ref="templateResolver" /> | |
</bean> | |
<bean class="org.thymeleaf.spring5.view.ThymeleafViewResolver"> | |
<property name="templateEngine" ref="templateEngine" /> | |
</bean> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" | |
xmlns:th="http://www.thymeleaf.org"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Title</title> | |
</head> | |
<body> | |
<h1>Hello world desde Spring - Home</h1> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package pe.cjjc.projects.controller; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
@Controller | |
public class HomeController | |
{ | |
@RequestMapping ("/") | |
public String home () | |
{ | |
return "home"; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>pe.cjjc.projects</groupId> | |
<artifactId>spring-mvc-cjjc-00</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
<name>spring-mvc-cjjc-00</name> | |
<packaging>war</packaging> | |
<properties> | |
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | |
<maven.compiler.target>17</maven.compiler.target> | |
<maven.compiler.source>17</maven.compiler.source> | |
</properties> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-webmvc</artifactId> | |
<version>5.3.23</version> | |
</dependency> | |
<dependency> | |
<groupId>org.thymeleaf</groupId> | |
<artifactId>thymeleaf</artifactId> | |
<version>3.0.11.RELEASE</version> | |
</dependency> | |
<dependency> | |
<groupId>org.thymeleaf</groupId> | |
<artifactId>thymeleaf-spring5</artifactId> | |
<version>3.0.11.RELEASE</version> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.apache.maven.plugins</groupId> | |
<artifactId>maven-war-plugin</artifactId> | |
<version>3.2.3</version> | |
<configuration> | |
<failOnMissingWebXml>false</failOnMissingWebXml> | |
</configuration> | |
</plugin> | |
</plugins> | |
</build> | |
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns="http://xmlns.jcp.org/xml/ns/javaee" | |
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" | |
id="spring-mvc-cjjc-00" | |
version="4.0"> | |
<display-name>spring-mvc-cjjc-00</display-name> | |
<session-config> | |
<session-timeout>30</session-timeout> | |
</session-config> | |
<servlet> | |
<servlet-name>dispatcher</servlet-name> | |
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> | |
<load-on-startup>1</load-on-startup> | |
</servlet> | |
<servlet-mapping> | |
<servlet-name>dispatcher</servlet-name> | |
<url-pattern>/</url-pattern> | |
</servlet-mapping> | |
</web-app> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment