找不到Thymeleaf模板/视图 - 春天4

时间:2017-03-15 14:32:41

标签: java spring spring-mvc thymeleaf

我正在使用Thymeleaf设置新的SPring4应用,并在返回视图时遇到同样的问题。我已经在这里搜索了并且遵循了一些在线教程,但是同样的错误,所以我认为这可能是由于配置,任何帮助都表示赞赏,谢谢。

错误:CREATE INDEX inx_username ON table (username);

然后我的配置是:

Web.xml中:

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "index", template might not exist or might not be accessible by any of the configured Template Resolvers

mcv.xml:

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


<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<!-- Use the simplified configuration by default. -->
<context-param>
    <param-name>spring.profiles.default</param-name>
    <param-value>simple</param-value>
</context-param>

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

<servlet>
    <servlet-name>Test</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <init-param>
        <param-name>spring.profiles.default</param-name>
        <param-value>simple</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>

<display-name>Test Web Application</display-name>

rootcontext.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/>

    <!--Allows for static content to easily be served up without needing a controller etc-->
    <mvc:resources mapping="/images/**" location="/assets/img/"/>
    <mvc:resources mapping="/css/" location="/assets/css/"/>
    <mvc:resources mapping="/assets/**" location="/assets/"/>

    <!--taken from the thymeleaf site-->
    <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" />
        <property name="cacheable" value="false" />
    </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>

编辑:

控制器:

    <?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"
    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">


    <import resource="mvc.xml" />

    <!--double asterisk allows for recursive search - load all under the pacakge-->
    <context:component-scan
            base-package="
                com.example.*"/>

    <context:property-placeholder location="classpath:application.properties"/>


</beans>

@EnableAutoConfiguration 公共类EmrController {

@Controller //restcontroller is not meant to be for returning view, but instead the data http://stackoverflow.com/questions/33062509/returning-view-from-spring-mvc-restcontroller

0 个答案:

没有答案