Раскладка тимьяна 404 не найдена - PullRequest
0 голосов
/ 30 мая 2018

Я установил все зависимости и следовал инструкциям, но шаблон не является страницей с шаблоном, не загружается и дает мне: 404. Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Я следил за этой страницей дляустановка: https://ultraq.github.io/thymeleaf-layout-dialect/Installation.html

Я использую Thymeleaf 3.0.9 (установлены зависимости) и версию 2.3.0 зависимостей thymleaf-dialect.

Если вынуть <bean></bean> (находится на странице установки), страница загружается без шаблона.Это остальная часть файла config-mvc.xml, в котором находятся компоненты:

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns="http://www.springframework.org/schema/beans"
   xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">

<mvc:annotation-driven/>

<mvc:resources mapping="/resources/**" location="/resources/"/>

<!-- **************************************************************** -->
<!--  THYMELEAF-SPECIFIC ARTIFACTS                                    -->
<!--  TemplateResolver <- TemplateEngine <- ViewResolver              -->
<!-- **************************************************************** -->

<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.spring4.SpringTemplateEngine">
    <property name="templateResolver" ref="templateResolver" />
</bean>

<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
    <property name="templateEngine" ref="templateEngine" />
</bean>

Я что-то упустил?Я также использую последнюю версию Spring-framework.

РЕДАКТИРОВАТЬ:

Контроллер, который я пытаюсь достичь:

 @Controller
 public class HelloController {
     @RequestMapping(value = "/", method = RequestMethod.GET)
    public String hello(Model model) {
        int temp = (Math.random() <= 0.5) ? 1 : 2;
        if(temp == 1)
        {
            model.addAttribute("template", "template");
        } else
        {
            model.addAttribute("template", "admintemplate");
        }
        return "home";
    }
}

My web.xml:

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xmlns="http://java.sun.com/xml/ns/javaee"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
     version="2.5">

<display-name>Hello Spring MVC</display-name>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/appconfig-root.xml</param-value>
</context-param>
<bean class="nz.net.ultraq.thymeleaf.LayoutDialect">
    <constructor-arg ref="groupingStrategy"/>
</bean>
<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Редактировать: Модель, которую я отправляю обратно, хранит данные (видимые при отладке).Я даю ему имя шаблона, но оно не помещается между $ {}.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...