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. QString int

    QString转int 直接调用toInt()函数 例: QString str("100"); int tmp = str.toInt(); 或者: bool ok; QStri ...

  2. osg创建灯光

    添加光照 osg::ref_ptr<osg::Node> MyOSGLoadEarth::CreateNode() { osg::ref_ptr<osg::Group> _ro ...

  3. 【设备问题】罗技M590鼠标无法连接Macbook Pro问题解决

    问题现象 罗技蓝牙鼠标连接的时候一直显示连接中,但是一直连接不上. 解决方法 长按那个切换模式的按钮,重置下,再点击连接,显示能够连接成功.

  4. python学习:python打包成exe

    1) 安装pyinstaller pip install pyinstaller 目前已经支持 python 3.7 版本 2) 打开cmd窗口,进入到要打包的python文件所在目录, pyinst ...

  5. Django安全配置(settings.py)详解

    必须配置项 PASSWORD_HASHER 这个配置是在使用Django自带的密码加密函数的时候会使用的加密算法的列表.默认如下: PASSWORD_HASHERS = ( 'django.contr ...

  6. Nginx配置自定义的403页面

    1.开启nginx的状态码,虚拟主机配置中加入下边一段 location /nginx_status{ stub_status on; access_log off; } 或着在nginx的http模 ...

  7. 修改ecshop的70种技巧

    1.如何修改网站”欢迎惠临本店”答复(dafu):languages\zh_cn\common.php文件中,$_LANG['welcome']=’欢迎惠临本店’:将他修改成你需要的字样. 2.如何修 ...

  8. Center Message

    企鹅号 头条号 大鱼号 百家号 趣头条

  9. PMP备考笔记--1.1

    题型 200道中英文单选题 基本概念题(%10) 过程工具/技术和输入输出题ITTO (%10) 情景题(%70) 计算题(3-5道题) 图 pmp四大挑战 试卷100页,题干长,阅读量大,考试4个小 ...

  10. Flask项目中使用mysql数据库启动项目是发出警告

    Flask项目中使用mysql数据库启动项目是发出警告: Warning: (1366, "Incorrect string value: '\xD6\xD0\xB9\xFA\xB1\xEA ...