一、问题描述
这是我的controller。传递了一个list给前台页面
@GetMapping(path = "/",produces = "text/json;charset=UTF-8")
public ModelAndView index() {
ModelAndView model =new ModelAndView();
try{
List<String> list = productService.getAllYear();
model.addObject("years",list);
model.setViewName("index");
}catch (Exception e) {
e.printStackTrace();
model.addObject("error",ERROR_INFO);
model.setViewName("error");
}
return model;
}
这是我的前台页面的主要代码
<a href="months" th:each="year : ${years}" th:text="${year}+'年'"class="list-group-item"></a>
二、需求描述
我想在 href 中,根据 ${year}的值动态生成url 。 例如生成 months/2017。 请问怎么做?就使用thymeleaf 的语法可以做吗? 或者有其他做法?
示例:
