【问题标题】:Thymeleaf Spring 4 can't render Expression LanguageThymeleaf Spring 4 无法渲染表达式语言
【发布时间】:2016-05-08 11:57:03
【问题描述】:

我集成了 Spring 4 MVC 和 Thymeleaf。我成功地获得了基于我的控制器的活动模板。 但是当我将请求属性添加到我的视图时,我的请求属性无法呈现该值。 我认为它是自动的。

这是我的 XML 配置文件:

<context:component-scan base-package="com.fanjavaid" />
    <mvc:annotation-driven />
    <mvc:resources location="/resources/" mapping="/resources/**" />

    <!-- THYMELEAF CONFIGURATION -->
    <bean id="templateResolver"
        class="org.thymeleaf.templateresolver.ServletContextTemplateResolver">
        <property name="prefix" value="/WEB-INF/views/"></property>
        <property name="suffix" value=".html"></property>
        <property name="templateMode" value="HTML5"></property> 
    </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"></property>
    </bean>

这是我的控制器:

@Controller
public class JobseekerController {
    @RequestMapping("/")
    public String index(Model model) {
        model.addAttribute("message", "Welcome to Spring 4 MVC");
        return "index";
    }
}

这是我的观点:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Welcome Page</title>
</head>
<body>
    <h1>${message}</h1>
</body>
</html>

我的视图是 HTML 文件。

【问题讨论】:

  • 试试这个:&lt;h1 th:text="${message}"&gt; Message &lt;/h1&gt; 并查看更多Info

标签: spring spring-mvc thymeleaf


【解决方案1】:

fanjavaid,

我只是认为您需要添加一些代码。

HTML

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>TEST</title>
</head>
<body>
<h1 th:text="${message}">hi</h1>



</body>
</html>

你搜百里香教程

【讨论】:

    猜你喜欢
    • 2015-12-31
    • 1970-01-01
    • 2016-04-20
    • 2016-06-15
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 2016-01-26
    • 2015-06-14
    相关资源
    最近更新 更多