SpringBoot,Thymeleaf th:text=${name}获取不到后端传过来的值 5

后台代码:@Controller//标明这是一个SpringMVC的Controller控制器@RequestMapping("/syj")publicclassTest... 后台代码:
@Controller // 标明这是一个SpringMVC的Controller控制器
@RequestMapping("/syj")
public class TestJspController {

@RequestMapping("/helloa")
public ModelAndView gg2(ModelAndView mv,HttpServletRequest request,HttpSession session ){
session.setAttribute("kk", "金合欢花或或");
request.setAttribute("key", "神学集团克东");
mv.setViewName("home/aaa");
mv.addObject("title","欢迎使用Thymeleaf!");
return mv;
}
前台:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" >
<head>
<title>Good Thymes Virtual Grocery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>

<body>
<div th:text="${session.kk}">测试session</div>
<h1 th:inline="text" >
<p th:text="${key}" th:remove="tag">Welcome to our grocery store!</p>
</h1>

<p th:text="${title}">Welcome to our grocery store!</p>

<h1>
<span th:text="${key}" th:remove="tag">title</span>
<small th:text="${key}" >Subtitle</small>
</h1>

</body>

</html>
</html>
配置文件
spring.thymeleaf.prefix=classpath:/jsp/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.cache=false
spring.resources.chain.strategy.content.enabled=false
spring.resources.chain.strategy.content.paths=/**
MAVen 部分依赖
<groupId>org.thymeleaF</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>3.0.9.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
展开
 我来答
s小明欧巴
2018-12-06
知道答主
回答量:1
采纳率:0%
帮助的人:778
展开全部
我也遇到这个问题,后来找了一圈终于得到结果:
<html lang="en"
xmlns:th="http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd" >
配置成这样并且:html内没有 xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"这两句时
在idea中使用thymeleaf的静态标签会显示报错。
第一次回答:望采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
泥土中的露珠
2018-09-16 · TA获得超过2.7万个赞
知道小有建树答主
回答量:1136
采纳率:100%
帮助的人:478万
展开全部
你的前台文件没有,th:text=${name}
是不是写错了?
本回答被网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式