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> 展开
@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> 展开
2个回答
展开全部
我也遇到这个问题,后来找了一圈终于得到结果:
<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的静态标签会显示报错。
第一次回答:望采纳
<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的静态标签会显示报错。
第一次回答:望采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你的前台文件没有,th:text=${name}
是不是写错了?
是不是写错了?
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询