
那是一定的。@RestController=@Controller+@ResponseBody,函数返回值会被当成responsebody来处理,因此如果需要返回页面,需要使用@Controller。
先看java部分
pomxml 加入
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!--支持
Web 应用开发,包含 Tomcat 和 spring-mvc。 -->
<dependency>
<groupId>orgspringframeworkboot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>orgspringframeworkboot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!--模板引擎-->
<div class="form-group">
<label>年龄</label> <select class="form-control" id="age">
<option value="1" th:selected="${sex=='1'}">男</option>
<option value="2" th:selected="${sex=='2'}">女</option>
</select></div>
Thymeleaf是XML/XHTML/HTML5的模板引擎,可以用在Web与非Web应用上。
Thymeleaf提供一种可被浏览器正确显示的、格式良好的模板创建方式,也可以用作静态建模。可以使用它创建经过验证的XML与HTML模板。开发者只需将标签属性添加到模板中即可。这些标签属性会在DOM(文档对象模型)上执行预先制定好的逻辑。可以使用它定义自己的模板属性集合,这样一来就可以计算自定义表达式并使用自定义逻辑。
Thymeleaf的模板也可以用作工作原型,Thymeleaf会在运行期替换掉静态值。
<!-- href里面用后台传值加字符拼接,或者直接是th:href="@{#index_id}" -->
<a th:href="@{'#'+${index_id_name}}" >123</a>
<!-- 要跳转的div -->
<div class="" style="height: 500px;background-color: #0088CC;">
<div id="index_id">
234
</div>
</div>
<!-- index_id_name的值为index_id -->
一、通用的thymeleaf模板引擎通过returnmodel和view获取后台返回的数据。项目中的pomxml文件引用了与thymeleaf相关的包。
二、在相应的controller方法中设置要返回的数据。
三、在HTML页面上引用thymeleaf标记。
四、引用controller在HTML标记中返回的数据。
五、返回的controller可以在JS中获取。
以上就是关于springboot thymeleaf返回的都是字符串不是页面全部的内容,包括:springboot thymeleaf返回的都是字符串不是页面、请问Spring+Thymeleaf+Html 怎么用Session实现分页、怎么实现thymeleaf用标签给页面select下拉框赋值等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)