Spring MVC Model Attribute null

时间:2016-10-25 20:36:14

标签: spring-mvc spring-boot thymeleaf

我想在我的模板中为网址添加ID:

navbar-brand

在我的dashboard.html中,我想显示ID。

.navbar-default .navbar-brand {
    height: 20px; // your desired height
}

但生成的网址为@Controller public class DashboardController { @RequestMapping("/dashboard") public String index(Model model){ model.addAttribute("provider_id", "1"); return "dashboard"; } } 。为什么不显示我放入模型中的1?

2 个答案:

答案 0 :(得分:0)

我测试了这个,我无法重现这个问题,这对我来说非常好。请在此处分享完整的控制器代码和您的依赖项。 一个猜测,你的Model类的类型是org.springframework.ui.Model,对吗?

答案 1 :(得分:0)

你可以这样使用http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#link-urls

<!-- Will produce '/gtvg/order/3/details' (plus rewriting) -->
<a href="details.html" th:href="@{/order/{orderId}/details(orderId=${o.id})}">view</a>
相关问题