900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > java跳转html页面_springboot 2.0.8 跳转html页面

java跳转html页面_springboot 2.0.8 跳转html页面

时间:2022-05-13 10:07:26

相关推荐

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里面 这个一般是默认配置好了的,如果没有就要加上哦

就这样启动就行了 效果图如下

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。