您的位置:首页 > 编程语言 > Java开发

Springboot学习基础

2019-03-06 16:23 211 查看

1、SpringBoot简介

  • 1、简化spring开发的框架
  • 2、整合Spring全家桶(整合 ssh、ssm、安全、docker、缓存、权限、消息、分布式、监控)
  • 3、不需要直接启动tomcat,内嵌tomcat,通过main方法启动,部署jar包来运行整个项目
  • 4、整合SpringMVC
  • 5、以后互联网项目都面向SOA ===》 微服务 spring could
  • 6、几乎全部都是注释:@controller、@Request、@Response
  • 前后端分离:前端html和js通过前端技术实现,不适用任何后台相关技术,比如freemarker,velocity,jsp等,后端不用开发前端任何技术,只写接口即可。

2、微服务:

  • 微服务:一种架构风格,封装RPC远程调用
  • 原来的RPC通过http/webservice形式调用,用起来复杂度比较高,类似于直接用JDBC,后面发展到直接调用对象形式来调用微服务,

3、maven集成jar包:

  • 通过pom.xml集成各种包和插件
  • spring-boot-starter-web:集成了web的jar包

4、访问静态资源
resources/static: 图片放置到目录下下可以直接访问,路径以resources/statc为基础路径,请求时加上static下的路径即可
比如请求resources/static/img文件夹下1.jpg:http://localhost:8080/img/1.jpg

  • @SpringBootConfiguration:帮我们加入了EnableAutoConfiguration和ComponentScan,默认扫描当前包及以下的包,所以启动的main一般放到根包下面
  • @ComponentScan: 扫描包目录,如果和main的class不在一个根包下,则需要在main的class头部加入需要扫描的包
  • @EnableAutoConfiguration:自动配置,加入后会自动扫描mianclass下的包
  • @Controller:说明是Controller @Request @Response
  • @Resource: 注入bean,按照类型(byType)装配依赖对象 @Auto

wired: 注入bean,按照ByName自动注入依赖对象

5、freemaker:模板引擎(springboot推荐)
模板引擎是将动态页面静态化 ,伪html格式,提高搜索引擎搜索。 比如:freemarker、velocity,thymeleaf等
application.properties配置如下:

spring.freemarker.allow-request-override=false
spring.freemarker.cache=true
spring.freemarker.charset=utf-8
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.suffix=.ftl - 文件后缀名
spring.freemarker.template-loader-path=classpath:/templates/ -- 模板加载地址
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: