Spring-Boot学习(2)-----Spring-Boot-web学习
来源:互联网 发布:黑客命令 Mac 编辑:程序博客网 时间:2024/06/03 20:16
为了更上技术的革新,近期打算学习下spring-Boot跟Spring-Cloud。下面将记录下自己学习过程。Spring-boot系列学习源代码放在https://github.com/wenbo2018/spring-boot-learning,有需要的可以自行下载。
使用Spring-boot进行web开发是极其方便而且简单的,下面将展示使用Spring-boot进行web开发,本文以ftl作为模板技术进行展示。
1.maven依赖
只需要配置父模块spring-boot-starter-parent跟spring-boot-starter-web就可以发布一个简单的应用了。
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent><!-- Spring Boot web 依赖 --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId></dependency><!-- Spring Boot Freemarker 依赖 --><dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId></dependency>
2.配置文件
虽然Spring-boot极大简化了配置过程,但是还是需要一些简单的配置,spring-boot主要采用
application.properties和application.yaml配置文件进行配置,本文首先使用application.properties进行配置。application.properties放置于resources文件夹下面。
本文主要在application.properties配置ftl相关配置
#Freemarker 配置spring.freemarker.template-loader-path=classpath:/web/## 文件配置路径用于放置ftl文件文件夹,web文件夹在sources下spring.freemarker.cache=falsespring.freemarker.charset=UTF-8spring.freemarker.check-template-location=truespring.freemarker.content-type=text/htmlspring.freemarker.expose-request-attributes=truespring.freemarker.expose-session-attributes=truespring.freemarker.request-context-attribute=requestspring.freemarker.suffix=.ftl
3.java代码
新建一个UserController
@Controllerpublic class UserController { @RequestMapping("/ftl") public String testFreeMaker() { return "index"; }}
新建一个Application.class
@SpringBootApplicationpublic class Application { public static void main(String[] args) throws Exception { SpringApplication app = new SpringApplication(Application.class); app.run(args); }}
ftl文件在sources/web/index.ftl下。运行main函数,只需要在浏览器中输入http://localhost:8080/ftl就能看到返回页面,至于传值跟Spring MVC一样。
0 0
- Spring-Boot学习(2)-----Spring-Boot-web学习
- Spring boot学习(2)
- spring-boot学习笔记2
- Spring Boot学习(一)
- Spring Boot学习(一)
- Spring Boot学习(一)
- spring boot 学习(一)
- Spring boot学习(1)
- Spring Boot学习(一)
- Spring boot学习(3)
- spring-boot web测试层学习记录
- Spring boot学习笔记(2) 配置文件
- spring-boot 学习笔记(2)
- Spring boot 学习知识点
- spring-boot学习
- Spring Boot 学习(一)
- spring-boot学习笔记
- Spring Boot学习笔记
- 排序算法集合
- Linux查看文件中间行
- 一个有getMin功能的栈
- 全国各省市直辖市软考机构联系方式(办公电话、网址、联系邮箱)
- 杂谈:垃圾短信
- Spring-Boot学习(2)-----Spring-Boot-web学习
- 制作《邓选》电子版,驱出校门二十载,鸣冤叫屈无人问
- 《疯狂JAVA讲义》之三——环境配置
- 引用math.h的时候,数学函数报错为未定义的符号
- background的应用和雪碧图
- 【LeetCode笔记】Balanced Binary Tree 高度平衡二叉树
- nyoj-会场安排问题
- (转)智能投顾销售基金涉嫌违规,证监会正严查!这两家成典型
- windows 下react native App环境搭建问题总结