Spring Boot - 开发Web应用
为什么80%的码农都做不了架构师?>>>
原文
静态资源访问
Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则:
- /static
- /public
- /resources
- /META-INF/resources
渲染 web界面
spring boot 对以下模板引擎提供友好配置
- Thymeleaf
- FreeMarker
- Velocity
- Groovy
- Mustache
当你使用上述模板引擎中的任何一个,它们默认的模板配置路径为:src/main/resource/templates。这个路径可在后续各模板引擎的配置属性中修改。
配置 pom.xml
<!-- freemarker -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
编写 Controller映射
@RequestMapping("/")
public String index(ModelMap map) {map.addAttribute("host", "http://blog.didispace.com");return "index";
}
编写模板页面( resources/template/index.ftl)
<!DOCTYPE html>
<html>
<head lang="en"><meta charset="UTF-8" /><title></title>
</head>
<body>
FreeMarker模板引擎
<h1>${host}</h1>
</body>
</html>
application.properties
## h2数据库本地化
spring.datasource.url = jdbc:h2:file:E\:\\test\\db\\testdb
spring.datasource.username = sa
spring.datasource.password = sa
spring.datasource.driverClassName = org.h2.Driver### jpa 配置 ###
spring.jpa.hibernate.ddl-auto: update
# hibernate的命令策略,方便导入"_"命名的表
spring.jpa.hibernate.naming-strategy: org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.database: H2
spring.jpa.show-sql: true## Freemarker 配置
## 文件配置路径
#spring.velocity.resource-loader-path=classpath:/templates/
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=true
spring.freemarker.request-context-attribute=request
# 视图名后缀
spring.freemarker.suffix=.ftlserver.port=8123
debug=true
logging.file=E:/logs/log.out
配置热部署插件
第一种方式:springloaded (官方文档)
补全 pom文件
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><!-- 会在程序运行时下载此依赖包,暂时报错 --><dependencies><dependency><groupId>org.springframework</groupId><artifactId>springloaded</artifactId><version>1.2.6.RELEASE</version></dependency></dependencies><!-- 加上这个会自动给你打包--><!--<executions><execution><goals><goal>repackage</goal></goals></execution></executions>--></plugin></plugins>
</build>
第二种方式:spring-boot-devtools (官方文档)
pom文件
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-devtools</artifactId><optional>true</optional>
</dependency>
1 如果使用 maven启动,必须配置 maven插件的 fork选项:
<build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><configuration><fork>true</fork></configuration></plugin></plugins>
</build>
2 指定让 devtools 监听指定文件夹,那么可以在 application.yml 配置spring.devtools.restart.additional-paths=your path,注意这里需要改成 yml 文件的格式。如果需要排除一些资源,可以使用:
spring.devtools.restart.exclude=static/**,public/**
3 spring-boot 包含一个内嵌的服务器,用于资源改变时触发浏览器刷新。可以设置spring.devtools.livereload.enabled property to false关闭它。
4. 配置好,你可以 Ctrl + S 保存,或者 Ctrl + shift + F9(Recompile),以便触发更新。
转载于:https://my.oschina.net/lemos/blog/829649
Spring Boot - 开发Web应用相关推荐
- html资源文件放在哪里,09 Spring Boot开发web项目之静态资源放哪里?
Spring Boot开发web项目之静态资源放哪里? 先了解自动装配autoconfiguration 这些内容是spring boot天然集成好的框架 找到WebMvcAutoConfigrati ...
- Spring Boot 开发web网页(helloworld为例)
Spring Boot 开发入门--- helloworld web 一.使用IntellijIDEA建立第一个spring boot 项目(helloworld) 1.创建一个spring boot ...
- 使用Spring Boot开发Web项目
前面两篇博客中我们简单介绍了spring Boot项目的创建.并且也带小伙伴们来DIY了一个Spring Boot自动配置功能,那么这些东西说到底最终还是要回归到Web上才能体现出它的更大的价值,so ...
- Spring Boot 开发web 项目
可参考博文: 搭建Spring Boot 项目 使用idea解决新建jsp文件而找不到jsp文件模版的新建选项 (一)快速搭建Web 项目 博主使用的是IDEA ,下面是项目目录结构:在用IDEA 创 ...
- Spring Boot开发Web应用
Spring Boot快速入门中我们完成了一个简单的RESTful Service,体验了快速开发的特性.在留言中也有朋友提到如何把处理结果渲染到页面上.那么本篇就在上篇基础上介绍一下如何进行Web应 ...
- Spring Boot之Web开发
Web开发 简单了解 快速上手 JSON 的支持 RESTful 的支持 支持热部署 快速上手 拦截器与过滤器 自定义过滤器 示例 自定义拦截器 示例 打包部署 多环境配置 服务器配置 项目打包 简单 ...
- 【spring boot】第3篇:spring boot 进行 web 开发
spring boot 对 web 静态资源的管理 经过前两篇文章我们知道spring boot最大的功能就是自动配置.主要是通过以下两个类实现该功能: xxxxAutoConfiguration : ...
- Spring Boot(5) web开发(3)拦截器、文件上传、异常处理
Spring Boot(5) web开发(3)拦截器.文件上传.异常处理 学习视频: https://www.bilibili.com/video/BV19K4y1L7MT?p=49&spm_ ...
- springboot thymeleaf配置_【程序源代码】Spring Boot 开发笔记web开发实战1
关键字:<Spring Boot 开发笔记>系列文章 各位亲爱的小伙伴:大家好! <Spring Boot 开发笔记>系列文章 这套笔记和源码是我自己在学习springboot ...
最新文章
- 稳压源GWINSTEKGPD3303系列控制软件
- 机器学习的5个成功案例
- 使用动态解析设置***
- 路由器的转发能力PPS
- An error occurred during the file system check
- 抵御故障引发系统性失控的基本原则:混沌工程
- struts2处理上传文件路径问题
- Java谜题:等于,还是不等于?
- linux驱动开发的经典书籍
- shell的变量以及常见符号
- OLAP组件-Clickhouse源码
- lambda java 表达式_Java中的Lambda表达式
- 磊科路由器怎么设置虚拟服务器,磊科无线路由器静态IP地址分配如何配置
- 少林禅医:姜是无上养生物,谨慎使用大智慧
- 数据结构与算法介绍与学习路线
- Average (区间最大均值,二分)
- android:layout_height=match_parent和android:layout_marginTop=100dp同时作用
- 如何在 R 中计算 Eta 平方
- 猿人学web端爬虫攻防大赛赛题解析_第九题:js混淆-动态cookie2
- 为pr视频文件添加字幕
热门文章
- linux安装python_Linux下安装python环境
- 鸿蒙系统手机现在有什么,华为鸿蒙手机迟迟未来 手机操作系统面临的难点有哪些...
- Java讲课笔记11:构造方法与this关键字
- 数据库笔记12:创建与管理触发器
- 漫谈OI中的群论入门
- 2017.10.24 上升序列 思考记录
- 每日小记2017.2.20
- Intel® Nehalem/Westmere架构/微架构/流水线 (4) - 执行引擎
- python r语言 数据分析_R vs. Python,数据分析中谁与争锋?
- python最大公约数计算_使用Python求解最大公约数的实现方法