本文摘自PHP中文网,作者醉折花枝作酒筹,侵删。
本篇文章给大家介绍一下springboot返回html和jsp的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
一、返回html
(1)添加maven依赖
1 2 3 4 | <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
|
(2)thymeleaf模板默认寻找resources下,templates文件夹放html页面,static文件夹放css及js

(3)引入js,需要使用如下格式
1 2 3 4 5 6 7 8 9 | <html lang= "en" xmlns:th= "http://www.thymeleaf.org" >
<script type= "text/javascript" th:src= "@{/js/jquery/jquery.min.js}" ></script>
<script type= "text/javascript" th:src= "@{/js/jquery/jquery.easyui.min.1-7-5.js}" ></script>
<script type= "text/javascript" th:src= "@{/js/jquery/easyui-lang-zh_CN.js}" ></script>
<script type= "text/javascript" th:src= "@{/js/index.js}" ></script>
<body>
<h2>Hello World!</h2>
</body>
</html>
|

(4)controller代码如下
1 2 3 4 5 6 7 8 9 10 11 12 | package springboot.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HtmlController {
@RequestMapping( "/show" )
public String show () {
return "aaa" ;
}
}
|
二、返回jsp
(1)添加jsp的maven依赖
1 2 3 4 5 6 7 8 9 | < dependency >
< groupId >org.apache.tomcat.embed</ groupId >
< artifactId >tomcat-embed-jasper</ artifactId >
< scope >provided</ scope >
</ dependency >
< dependency >
< groupId >javax.servlet</ groupId >
< artifactId >jstl</ artifactId >
</ dependency >
|
注:返回jsp需要把spring-boot-starter-thymeleaf注释掉
阅读剩余部分
相关阅读 >>
html中的caption属性是什么意思?caption标签在html中的用法(附实例)
html和url有什么区别么
html是什么意思英语
jsp里面怎么写javascript
html怎么改变标签的字体
html5实现移动端下拉刷新(原理和代码)
html如何创建电子邮件链接
html文件以什么结尾
父元素<a>标签的默认行为以及click事件之间的相互影响
html怎么加入js
更多相关阅读请进入《springBoot》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » springboot如何返回html和jsp