springboot学习入门简易版四---springboot2.0静态资源访问及整合freemarker视图层
2.4.4 SpringBoot静态资源访问(9)
Springboot默认提供静态资源目录位置需放在classpath下,目录名需要符合如下规则
/static /public /resources /META-INF/resources
可以在src/main/resources目录下创建static,在该位置放置一个图片文件。
启动程序后,尝试访问http://localhost:8080/D.JPG,如能显示图片,配置成功。
2.5 SpringBoot整合freemarker视图层(10)
项目结构

1 pom文件
<!-- spring-boot-starter-parent 整合第三方常用框架依赖信息(包含各种依赖信息) -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.0.RELEASE</version>
</parent> <!-- spring-boot-starter-web springboot整合springmvc web
实现原理:maven依赖继承关系,相当于把第三方常用maven依赖信息,在parent项目中已封装
-->
<dependencies>
<!-- 根据需要选择parent中封装的第三方框架 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 不需要写版本号,因为在parent中已封装好版本号 -->
</dependency> <!-- freemarker依赖包 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
2创建controller类
@Controller //注意:不能使用@RestController(没有视图层),否则无法找到对应的ftl模板,类似jsp
public class FtlController { @RequestMapping("/ftlIndex")
public String ftlIndex(Map<String, Object> map) {
map.put("name", "test");//相当于request.setName()
map.put("age", "2");
return "ftlIndex";//自动查找对应的页面,类似jsp
} }
3创建ftl模板

必须在templates目录下,且ftl文件名和controller类中的return "ftlIndex"名一致才能匹配。
模板内容如下:${name}====${age}

4启动项目并访问:
http://localhost:8080/ftlIndex
页面显示:freemarker页面 test====2
springboot学习入门简易版四---springboot2.0静态资源访问及整合freemarker视图层的更多相关文章
- springboot学习入门简易版八---springboot2.0多环境配置、整合mybatis mysql8+(19-20)
2.11 SpringBoot多环境配置(19) application.properties中配置 Spring.profiles.active=prd 配置环境: Application-dev ...
- springboot学习入门简易版三---springboot2.0启动方式
2.4使用@componentscan方式启动 2.4.1 @EnableAutoConfiguration 默认只扫描当前类 @EnableAutoConfiguration 默认只扫描当前类,如果 ...
- springboot学习入门简易版二---springboot2.0项目创建
2 springboot项目创建(5) 环境要求:jdk1.8+ 项目结构: 2.1创建maven工程 Group id :com.springbootdemo Artifact id: spring ...
- springboot学习入门简易版六---springboot2.0整合全局捕获异常及log4j日志(12-13)
使用Aop实现 1创建异常请求 在原有项目基础上,jspController中创建一个可能发生异常的请求: /** * 全局捕获异常测试 * @param i * @return */ @Reques ...
- springboot学习入门简易版五---springboot2.0整合jsp(11)
springboot对jsp支持不友好,内部tomcat对jsp不支持,需要使用外部tomcat,且必须打包为war包. 1 创建maven项目 注意:必须为war类型,否则找不到页面. 且不要把js ...
- springboot学习入门简易版九---springboot2.0整合多数据源mybatis mysql8+(22)
一个项目中配置多个数据源(链接不同库jdbc),无限大,具体多少根据内存大小 项目中多数据源如何划分:分包名(业务)或注解方式.分包名方式类似多个不同的jar,同业务需求放一个包中. 分包方式配置多数 ...
- springboot学习入门简易版一---springboot2.0介绍
1.1为什么用springboot(2) 传统项目,整合ssm或ssh,配置文件,jar冲突,整合麻烦.Tomcat容器加载web.xml配置内容 springboot完全采用注解化(使用注解方式启动 ...
- springboot学习入门简易版七---springboot2.0使用@Async异步执行方法(17)
1启动类开启异步调用注解 @SpringBootApplication @EnableAsync //开启异步调用 public class StartApplication { 不开启则异步调用无效 ...
- SpringBoot 2.x 自定义拦截器并解决静态资源访问被拦截问题
自定义拦截器 /** * UserSecurityInterceptor * Created with IntelliJ IDEA. * Author: yangyongkang * Date: ...
随机推荐
- dart里面的时间处理:
原文地址:https://www.cnblogs.com/wyhlightstar/p/11059942.html 1.获取当前时间 var now = new DateTime.now(); pri ...
- Django Timezone 处理
https://blog.csdn.net/qq_37049781/article/details/79347278 Django 中的时区在现实环境中,存在有多个时区.用户之间很有可能存在于不同的时 ...
- SQL语句精妙集合
1一.基础 2 31.说明:创建数据库 4Create DATABASE database-name 5 62.说明:删除数据库 7drop database dbname 8 93. ...
- 【翻译】Flink Joining
本文来自官网翻译: Joining Window Join(窗口join) Tumbling Window Join(翻滚窗口join) Sliding Window Join(滑动窗口join) S ...
- [ kvm ] 学习笔记 6:virsh 命令及功能详解
1. 虚拟机管理操作 attach-device 从XML文件附加设备 attach-disk 附加磁盘设备 attach-interface 连接网络接口 autostart 自动启动一个域 blk ...
- LODOP的ADD_PRINT_TABLE中不能总计在最后一页显示在tfoot后面
ADD_PRINT_TABLE有计算功能,还会每页显示tfoot和thead里的内容.相关其他博文:如果一个表格既有需要每页显示的tfoot,还有一个总计功能,想显示在最后一页的tfoot后面,是不行 ...
- 【Leetcode_easy】925. Long Pressed Name
problem 925. Long Pressed Name solution1: class Solution { public: bool isLongPressedName(string nam ...
- PNG压缩工具-PNGGauntlet
PNGGauntlet下载地址 对于前端来说非常实用的PNG压缩软件,支持拖拽,就是软件速度比较慢.
- Docker:学习笔记(1)——基础概念
Docker:学习笔记(1)——基础概念 Docker是什么 软件开发后,我们需要在测试电脑.客户电脑.服务器安装运行,用户计算机的环境各不相同,所以需要进行各自的环境配置,耗时耗力.为了解决这个问题 ...
- iOS 多线程的简单理解(3)执行方式 + 执行对列 的组合
通过对前面两偏线程理解的总结,自己对线程的理解也逐渐加深,梳理的清晰起来…… 通常在使用线程 的时候,都是要用到 执行对列,执行方式,执行任务, 现在开始新一轮的深入 3. 1. 1 同步 + 串行 ...