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视图层的更多相关文章

  1. springboot学习入门简易版八---springboot2.0多环境配置、整合mybatis mysql8+(19-20)

    2.11 SpringBoot多环境配置(19)  application.properties中配置 Spring.profiles.active=prd 配置环境: Application-dev ...

  2. springboot学习入门简易版三---springboot2.0启动方式

    2.4使用@componentscan方式启动 2.4.1 @EnableAutoConfiguration 默认只扫描当前类 @EnableAutoConfiguration 默认只扫描当前类,如果 ...

  3. springboot学习入门简易版二---springboot2.0项目创建

    2 springboot项目创建(5) 环境要求:jdk1.8+ 项目结构: 2.1创建maven工程 Group id :com.springbootdemo Artifact id: spring ...

  4. springboot学习入门简易版六---springboot2.0整合全局捕获异常及log4j日志(12-13)

    使用Aop实现 1创建异常请求 在原有项目基础上,jspController中创建一个可能发生异常的请求: /** * 全局捕获异常测试 * @param i * @return */ @Reques ...

  5. springboot学习入门简易版五---springboot2.0整合jsp(11)

    springboot对jsp支持不友好,内部tomcat对jsp不支持,需要使用外部tomcat,且必须打包为war包. 1 创建maven项目 注意:必须为war类型,否则找不到页面. 且不要把js ...

  6. springboot学习入门简易版九---springboot2.0整合多数据源mybatis mysql8+(22)

    一个项目中配置多个数据源(链接不同库jdbc),无限大,具体多少根据内存大小 项目中多数据源如何划分:分包名(业务)或注解方式.分包名方式类似多个不同的jar,同业务需求放一个包中. 分包方式配置多数 ...

  7. springboot学习入门简易版一---springboot2.0介绍

    1.1为什么用springboot(2) 传统项目,整合ssm或ssh,配置文件,jar冲突,整合麻烦.Tomcat容器加载web.xml配置内容 springboot完全采用注解化(使用注解方式启动 ...

  8. springboot学习入门简易版七---springboot2.0使用@Async异步执行方法(17)

    1启动类开启异步调用注解 @SpringBootApplication @EnableAsync //开启异步调用 public class StartApplication { 不开启则异步调用无效 ...

  9. SpringBoot 2.x 自定义拦截器并解决静态资源访问被拦截问题

      自定义拦截器 /** * UserSecurityInterceptor * Created with IntelliJ IDEA. * Author: yangyongkang * Date: ...

随机推荐

  1. 查看所使用的Linux系统是32位还是64 位的方法

    方法一:getconf LONG_BIT # getconf LONG_BIT 1 1 我的Linux是32位!!! 方法二:arch # arch 1 1 显示 i686 就是32位,显示 x86_ ...

  2. 编译Flink 1.9.0

    闲来无事,编个Flink 1.9 玩玩 1.下载flink.flink-shaded 源码.解压 flink flink-shaded 7.0 [venn@venn release]$ ll tota ...

  3. 服务发现--初识Consul

    前言 服务注册.服务发现作为构建微服务架构得基础设施环节,重要性不言而喻.在当下,比较热门用于做服务注册和发现的开源项目包括zookeeper.etcd.euerka和consul.今天在这里对近期学 ...

  4. linux中信号的API详解实例

    /************************************************************************* > File Name: signal.c ...

  5. Codeforces-Two Buttons-520problemB(思维题)

    B. Two Buttons Vasya has found a strange device. On the front panel of a device there are: a red but ...

  6. todo---git 生成密钥 原理分析

    ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDRJkDZ2z7syFC2QDCaORKF41ecwbL/kyFwkycOVE3MavTRBliAhoAhOaZQTr4j ...

  7. linux服务器安装jdk (手动解压方式安装)

    linux服务器安装jdk 使用的是通过手动解压安装的方式,没有通过yum或者apt-get命令安装 准备: 下载一个jdk,版本自选,后缀为(.tar.gz) 开始 创建目录 mkdir /usr/ ...

  8. C++_向函数传递对象

    向函数传递对象 1. 使用对象作为函数参数 对象可以作为参数传递给函数,其方法与传递其他类型的数据相同. 在向函数传递对象时,是通过传值调用传递给函数的. 因此,函数中对对象的任何修改均不影响调用该函 ...

  9. php数组指针函数

    数组指针函数有reset(),prev(),current(),next(),end(),key(),each() 其中reset(),prev(),current(),next(),end(),都是 ...

  10. Python re模块学习

    这是re模块与正则的结合 re模块提供的函数 1.match  尝试在字符串的开头应用该模式,返回匹配对象,如果没有找到匹配,则为None. import re str1 = "Why ar ...