未找到Thymeleaf布局404

时间:2018-05-30 14:48:22

标签: java spring thymeleaf

我已安装所有依赖项并遵循教程,但模板不是带有模板的页面没有加载并给我一个: 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>(在安装页面上找到),页面加载,没有模板。这是其中包含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框架。

编辑:

我想要达到的控制器:

 @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";
    }
}

我的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>

编辑:我发回的模型确实保存数据(通过调试看到)。我给它的模板名称,但它不会放在$ {}。

之间

0 个答案:

没有答案