本文摘自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单行怎么注释
html bdi标签怎么用
html怎么设置a标签居中
html如何设置禁止选中
html如何使用失去焦点属性onblur
html表单的基本元素
html如何实现点击下载文件功能
html以及css的常用用法
html怎么设置图片按钮
html表格怎么做
更多相关阅读请进入《springBoot》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » springboot如何返回html和jsp