springboot thymeleaf 生成静态html
2018-07-13 11:10
1586 查看
1.引入jar
2.模板文件(位置:resources/static/tempfiles)
3..在spring启动类中测试下
搞定收工!
<dependency> <groupId>ognl</groupId> <artifactId>ognl</artifactId> <version>3.2.6</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
2.模板文件(位置:resources/static/tempfiles)
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <title>欢迎页</title> <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport" /> <link rel="stylesheet" href="css/bootstrap.min.css" /> </head> <body> <div class="panel panel-default"> <div class="panel-heading">你好,<a th:text="${name}"></a></div> <div style="padding: 10px 0 20px 10px;"> </div> </div> </body> </html>
3..在spring启动类中测试下
@SpringBootApplication public class DemoStaticApplication { public static void main(String[] args) { SpringApplication.run(DemoStaticApplication.class, args); final String TEMPLATE_PREFIX = "static/tempfiles/"; final String TEMPLATE_SUFFIX = ".html";// try { ClassLoaderTemplateResolver resolver = new ClassLoaderTemplateResolver(); resolver.setPrefix(TEMPLATE_PREFIX); resolver.setSuffix(TEMPLATE_SUFFIX); TemplateEngine templateEngine = new TemplateEngine(); templateEngine.setTemplateResolver(resolver); //填充数据 Context context = new Context(); context.setVariable("name", "俩快线-俩快线"); //渲染模板生成静态 FileWriter writer = new FileWriter("d:/html/index.html"); templateEngine.process("temp", context, writer); } catch (Exception e) { System.out.println(e); } } }
搞定收工!
相关文章推荐
- springboot整合freemarker生成静态HTML页面
- Spring Boot使用freemarker并且生成静态html页面
- springboot 静态资源html,jsp,css
- SpringBoot 同时整合thymeleaf html、vue html和jsp-在线助手
- spring boot直接返回静态html
- [spring boot] 用 thymeleaf模板开发html页面
- spring boot 使用thymeleaf加载静态资源打成jar之后无法访问
- Spring boot+ maven + thymeleaf + HTML 实现简单的web项目
- Spring Boot+thymeleaf 静态资源上下文的问题
- spring boot结合thymeleaf通过后台传入的数值循环生成标签
- springboot-thymeleaf(html页面跳转)
- 简单快速的用SpringBoot访问静态资源(图片、html)
- (五)Spring Boot配置静态资源访问,整合Thymeleaf模板
- Spring Boot使用thymeleaf 解析html template时失败
- springboot如何使用thymeleaf模板访问html页面
- thymeleaf :springboot整合mybatis的web项目中使用html而不是jsp当页面渲染
- spring boot 访问静态html、js
- 【系统学习SpringBoot】初见Thymeleaf之SpringBoot访问项目中的 jsp/html
- spring boot 学习笔记(003) 静态资源(html/js等文件)
- 使用Spring计时器和velocity模板定时生成静态html/jsp文件