Spring MVC + Thymeleaf example!

Just for the fun of it.

pom.xml
<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/maven-v4_0_0.xsd">
 
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>biz.tugay</groupId>
    <artifactId>smvcpoc</artifactId>
 
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
 
    <name>smvcpoc Maven Webapp</name>
    <url>http://maven.apache.org</url>
 
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.0.5.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.0.0.RELEASE</version>
            <scope>compile</scope>
        </dependency>
 
        <dependency>
            <groupId>org.thymeleaf</groupId>
            <artifactId>thymeleaf-spring4</artifactId>
            <version>3.0.0.RELEASE</version>
        </dependency>
    </dependencies>
 
    <build>
        <finalName>smvcpoc</finalName>
        <plugins>
            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.2.1.v20140609</version>
                <configuration>
                    <scanIntervalSeconds>2</scanIntervalSeconds>
                    <webApp>
                        <contextPath>/</contextPath>
                    </webApp>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                             http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
         version="3.0">
 
    <servlet>
        <servlet-name>springDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/servletContext.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
 
    <servlet-mapping>
        <servlet-name>springDispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
 
</web-app>

servlet-context.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-4.0.xsd">
 
    <bean id="repidController" class="biz.tugay.RepidController" />
 
    <bean id="templateResolver"
          class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
        <constructor-arg ref="servletContext"/>
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".html" />
        <property name="templateMode" value="HTML5" />
    </bean>
 
    <bean id="templateEngine"
          class="org.thymeleaf.spring4.SpringTemplateEngine">
        <property name="templateResolver" ref="templateResolver" />
    </bean>
 
    <bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
        <property name="templateEngine" ref="templateEngine" />
    </bean>
</beans>

RepidController.java
package biz.tugay;
 
/* User: koray@tugay.biz Date: 2016/06/09 */
 
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
 
import java.io.File;
import java.io.IOException;
 
@Controller
@RequestMapping(value = "/repid")
public class RepidController {
    @RequestMapping(method = RequestMethod.GET, value = "/repidType")
    public String foo(Model model) throws IOException {
        final RepidTypeTable repidTypeTable = new RepidTypeTable(new File("zbde.meta"), new File("koray.txt"));
        model.addAttribute("repidTypeColumns", repidTypeTable.getRepidTypeTableColumns());
        model.addAttribute("repidTypeRows", repidTypeTable.getRepidTypeTableRows());
        return "index";
    }
}

index.html
<!DOCTYPE html>
<html lang="en"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <title>Repid Type POC</title>
    <style type="text/css">
        table {
            border-collapse: collapse;
        }
 
        th, td {
            padding: 5px 10px;
            border: 1px solid #999;
        }
 
        th {
            background-color: #eee;
        }
    </style>
</head>
<body>
<div>
    <!--@thymesVar id="repidTypeColumns" type="java.util.List<biz.tugay.RepidTypeTableColumn>"-->
    <!--@thymesVar id="repidTypeRows" type="java.util.List<biz.tugay.RepidTypeTableRow>"-->
    <table>
        <thead>
        <tr>
            <th th:each="repidTypeColumn : ${repidTypeColumns}" th:text="${repidTypeColumn.columnHeaderText}">
            </th>
        </tr>
        </thead>
        <tr th:each="repidTypeRow : ${repidTypeRows}">
            <td th:each="repidTypeCell : ${repidTypeRow.repidTypeTableCells}" th:text="${repidTypeCell.data}">
            </td>
        </tr>
    </table>
</div>
</body>
</html>