springboot如何使用velocity模版引擎
2017-06-13 21:31
381 查看
1.场景还原
由于公司项目是springboot构建的,访问静态资源必须是首要的考虑;但是springboot访问静态资源跟ssm中有些不一样的地方, 今天笔者就讲解一下在springboot工程中如何加载静态资源。2.实现方案
方案①:直接地址栏访问在工程的resources目录下新建static目录,将待访问的静态资源放进去
方案②:通过后台controller实现前端页面跳转
1>在pom.xml中加入velocity依赖( 模板引擎)
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-velocity</artifactId> </dependency>
2>在application.properities配置
spring.velocity.suffix=.html
3.在resources新建static,templates目录
static目录放静态文件(js,css,image之类),templates放模板文件(html,jsp)
注意:templates命名必须正确,里面的html中的资源引用不变,原前端工程怎么放就怎么放,资源路径写成未导入后端之前的样子
好了,访问效果:
大功告成,springboot的静态资源加载就说到这里了,我是张星,欢迎加入博主的技术交流群,群号:313145288
相关文章推荐
- springboot如何使用Freemarker模版引擎
- spring-boot+mybatis开发实战:如何在spring-boot中使用myabtis持久层框架
- 如何在SpringBoot中使用JSP ?但强烈不推荐,果断改Themeleaf吧
- 如何使用MongoDB+Springboot实现分布式ID?
- 详解如何在Spring Boot项目使用参数校验
- Spring Boot 中如何使用 Dubbo Activate 扩展点
- spring-boot+mybatis开发实战:如何在spring-boot中使用myabtis持久层框架
- (9) spring boot使用freemarker模板引擎
- spring boot如何使用spring AOP实现拦截器
- 如何在SpringBoot中使用JSP ?但强烈不推荐,果断改Themeleaf吧
- 如何使用Spring Boot快速创建Web应用
- 如何在Spring Boot项目使用参数校验
- 如何使用eclipse搭建SpringBoot项目
- 在Spring Boot中如何使用数据缓存
- Spring-Boot中如何使用多线程处理任务
- spring boot(六):如何优雅的使用mybatis
- SpringBoot使用thymeleaf模板引擎
- (3)spring boot如何使用第三方json解析框架
- Spring Boot 中如何使用 Dubbo Activate 扩展点
- Spring Boot 中如何使用 Dubbo Activate 扩展点