我试着用thymelaf呈现一个字符串数组,它显示为空白。有人知道原因吗?代码如下所示:
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
//public String[] greetings= new String[] {"Hi","Hello","Watsup"};
@RequestMapping("/home")
public String getHomePage(Model model) {
model.addAttribute("msg",new String[]{"Hi","Hello","Watsup"});
//model.addAttribute("msg",new String[]{"Hi","Hello","Watsup"});
return "home";
}
//<h1 th:text=${welcomeMessage}>*Hello Peeps!*</h1>
}```
the html(thymeleaf) is shown below:
<h1 th:each="msg : ${greetings}" th:text=${msg}>Hello,homepage</h1>
您通过"msg"钥匙你需要访问它而不是问候语。
<h1 th:each="message : ${msg}" th:text=${message}>Hello,homepage</h1>