java跳转html页面_springboot 2.0.8 跳转html页面
springboot 成功創建了后,繼續寫一下跳轉到html頁面的方法, ?這里我把 jsp和html 分開兩篇文章。然后再寫一個兩種方式整合的
這篇 是跳轉到html文件的
1創建目錄結果和html文件
?
2配置return 返回模版
?
3.UserController.java代碼如下,這里就直接使用上次創建的查詢方法
@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("進入了testHtml方法!"); return "views/testHtml"; }
4.application.yml 文件 配置?thymeleaf 模版參數
?
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 #非嚴格模式
prefix: /WEB-INF/ #默認 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頁面這里我為了方便事先引入了jQuery ,并且直接使用了thymeleaf 模版來接收數據,也是第一次用。
Title
7. Project Structure里面 這個一般是默認配置好了的,如果沒有就要加上哦
?
就這樣啟動就行了 ?效果圖如下
?
總結
以上是生活随笔為你收集整理的java跳转html页面_springboot 2.0.8 跳转html页面的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: 贪吃蛇html一维坐标,html贪吃蛇
- 下一篇: Power Bi:DAX函数总结
