java跳转html页面_springboot 2.0.8 跳转html页面
springboot 成功創(chuàng)建了后,繼續(xù)寫一下跳轉(zhuǎn)到html頁(yè)面的方法, ?這里我把 jsp和html 分開(kāi)兩篇文章。然后再寫一個(gè)兩種方式整合的
這篇 是跳轉(zhuǎn)到html文件的
1創(chuàng)建目錄結(jié)果和html文件
?
2配置return 返回模版
?
3.UserController.java代碼如下,這里就直接使用上次創(chuàng)建的查詢方法
@RequestMapping(value = "/testHtml", produces = "application/json;charset=UTF-8", method = {RequestMethod.POST, RequestMethod.GET})
public String testHtml(Model m, HttpServletRequest request, HttpServletResponse response){ List> list=userService.userQueryAll(); request.setAttribute("list",list); log.info("進(jìn)入了testHtml方法!"); return "views/testHtml"; }
4.application.yml 文件 配置?thymeleaf 模版參數(shù)
?
spring:
dataSource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/db-test?useUnicode=true&characterEncoding=utf8&tinyInt1isBit=false&usessl=false
username: root
password: 123456
driverClassName: com.mysql.jdbc.Driver
thymeleaf:
#清除緩存
cache: false
mode: LEGACYHTML5 #非嚴(yán)格模式
prefix: /WEB-INF/ #默認(rèn) classpath:/templates/
suffix: .html
servlet:
content-type: text/html
5. pom.xml 文件加入thymeleaf 架包
org.springframework.boot
spring-boot-starter-thymeleaf
net.sourceforge.nekohtml
nekohtml
1.9.22
6. html頁(yè)面這里我為了方便事先引入了jQuery ,并且直接使用了thymeleaf 模版來(lái)接收數(shù)據(jù),也是第一次用。
Title
7. Project Structure里面 這個(gè)一般是默認(rèn)配置好了的,如果沒(méi)有就要加上哦
?
就這樣啟動(dòng)就行了 ?效果圖如下
?
總結(jié)
以上是生活随笔為你收集整理的java跳转html页面_springboot 2.0.8 跳转html页面的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 贪吃蛇html一维坐标,html贪吃蛇
- 下一篇: Power Bi:DAX函数总结