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: ...
随机推荐
- 算法习题---5-5复合词(UVa10391)
一:题目 输入一系列由小写字母组成的单词.输入已按照字典序排序,且不超过120000个.找出所有的复合词,即恰好由两个单词连接而成的单词 (一)样例输入 a alien born less lien ...
- 转:HR schema
###createe RemRem $Header: hr_cre.sql 29-aug-2002.11:44:03 hyeh Exp $RemRem hr_cre.sqlRemRem Copyrig ...
- Linux系统调优——内核相关参数(五)
修改内核参数有3种办法:一种临时修改,两种永久修改. 临时修改是使用sysctl [选项] [参数名=值]命令:永久修改是修改/etc/sysctl.conf文件或修改/proc/sys/目录下的对应 ...
- ABAP DEMO ALVtree显示BOM层级
展示效果: *&---------------------------------------------------------------------* *& Report YCX ...
- (十三)class文件结构:常量池(转)
Class类文件的结构 全局规范 1.任何一个Class文件都对应着唯一一个类或接口的定义信息,但反过来说,类或接口并不一定都得定义在文件里(譬如类或接口也可以通过类加载器直接生成).本章中,只是通俗 ...
- 模仿系统C键功能菜单
1.可以拖拽C键 2.依赖zepto 3.点击弹出菜单 效果预览:
- Tomcat教程(转)
转载链接: https://www.cnblogs.com/jingmoxukong/p/8258837.html?utm_source=gold_browser_extension 简介 Tomca ...
- mysql数据库建表授权操作
1.create schema [数据库名称] default character set utf8 collate utf8_general_ci;--创建数据库 采用create schema和c ...
- Python文件的读取写入操作
一.打开文件.关闭文件操作 想要读取文件或是写入文件,第一步便是打开文件,最后一步便是关闭文件.这里介绍两种打开(关闭)文件的方式: 1.open()方法 f=open(file_name[,acce ...
- 一个容器多个进程,一个pod多个容器
一个容器多个进程:在Docker的镜像编译脚本Dockerfile中带起多个进程,如下可以在contivNet.sh中启动多个进程 FROM 10.37.210.125:5001/suning/cen ...