sts中thymeleaf中顯示不出來
我在sts中使用thymeleaf頁面起不了作用呢
application中的配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
spring.thymeleaf.cache=false
html頁面
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>
</head>
<body>
<h1 th:text="${hello}">Hello</h1>
</body>
</html>
控制器
@Controller
@EnableAutoConfiguration
public class StudentController {
@RequestMapping("/f")
public String free() {
Map<String,Object> map = new HashMap<String, Object>();
map.put("hello","user1");
return "freemarker/index";
}
}
}
頁面顯示不了user1
歡迎小伙伴速速解答
2019-07-23
你頁面中可以獲取Map中的值,頁面一般應該是獲取request域中的,在返回到頁面不重定向的情況下,重定向的情況,request域中的值會獲取不到,你這個直接返回到頁面,沒有把值放到request域中,或者放入model中也可