1、SpringBoot2.x依赖环境和版本新特性说明
1、依赖版本jdk8以上, Springboot2.x用JDK8, 因为底层是 Spring framework5,
2、安装maven最新版本,maven3.2以上版本,下载地址 :https://maven.apache.org/download.cgi
3、Eclipse或者IDE
4、新特性
5、翻译工具:https://translate.google.cn/
6、springbootGitHub地址:https://github.com/spring-projects/spring-boot
7、springboot官方文档:https://spring.io/guides/gs/spring-boot/
2、快速创建SpringBoot2.x应用
1、手工创建:http://spring.io/guides/gs/rest-service/(备注:网址已更新,与视频录制时不一样,笔记里为更新的网址)
官方推荐包命名接口,不要使用默认 defaultPackage
官方文档: https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#using-boot-using-the-default-package
2、工具自动创建:http://start.spring.io/
3、SpringBoot2.xHTTP请求配置讲解
简介:SpringBoot2.xHTTP请求注解讲解和简化注解配置技巧
1、@RestController 和@RequestMapping 是springMVC的注解,不是springboot特有的
2、@RestController = @Controller+@ResponseBody ,如果前后端分离且需要从后端传Json格式的数据就需要用@RestController ,否则报错
3、在SpringBoot默认启动类中使用可只引用@SpringBootApplication,也可引用如下三个,效果一致(如下图):
@SpringBootApplication = @Configuration+@EnableAutoConfiguration+@ComponentScan
4、SpringBoot基础HTTP接口GET请求实
简介:讲解springboot接口,http的get请求,各个注解使用
1、GET请求
1、单一参数@RequestMapping(path = "/{id}", method = RequestMethod.GET)
1) public String getUser(@PathVariable String id ) {}
2)@RequestMapping(path = "/{depid}/{userid}", method = RequestMethod.GET) 可以同时指定多个提交方法
getUser(@PathVariable("depid") String departmentID,@PathVariable("userid") String userid)
3)一个顶俩
@GetMapping = @RequestMapping(method = RequestMethod.GET)
@PostMapping = @RequestMapping(method = RequestMethod.POST)
@PutMapping = @RequestMapping(method = RequestMethod.PUT)
@DeleteMapping = @RequestMapping(method = RequestMethod.DELETE)
4)@RequestParam(value = "name", required = true)
可以设置默认值,比如分页
4)@RequestBody 请求体映射实体类
需要指定http头为 content-type为application/json charset=utf-8
5)@RequestHeader 请求头,比如鉴权
@RequestHeader("access_token") String accessToken
6)HttpServletRequest request自动注入获取参数
5、yml和propertise的区别
(1)、默认情况下是properties结尾的配置文件,都放在src/main/resources目录。
(2)、书写规范不一样
application.properties文件配置:
//随机端口号server.port=${random.int[1024,9999]}
server.port=9090
gx.msg=hi,hello world
转换为application.yml文件配置:
server:
port: 9090
gx:
msg: hi,hello world
以空格的缩进程度来控制层级关系,空格个数不重要。
(3)、加载顺序不同
正常的情况是先加载yml,接下来加载properties文件。如果相同的配置存在于两个文件中。最后会使用properties中的配置。最后读取的优先集最高。
6、SpringBoot思维导图
1.Spring boot 简介
2.Spring boot 的特性
3.Spring boot 开发环境
4.第一个 Spring boot 程序
5.第一个 Spring boot 程序解析
6.Spring boot 的核心配置文件
7.Spring boot 自定义配置
8.Spring boot 下的 Spring mvc
9.Spring boot 使用 JSP
10.Spring boot 集成 MyBatis
11.Spring boot 事务支持
12.Spring boot 实现 RESTfull API
13.Spring boot 热部署插件
14.Spring boot 集成 Redis
15.Spring boot 集成 Dubbo
16.Spring boot 使用拦截器
17.Spring boot 中使用 Servlet
18.Spring boot 中使用 Filter
19.Spring boot 项目配置字符编码
20.Spring Boot 非web应用程序
21.Spring boot 程序war包部署
22.Spring boot 程序打Jar包与运行
23.Spring boot 部署与运行方式总结
24.spring boot 集成 Spring session
26.Spring boot Actuator
27.Spring boot 综合案例
总结
(1)采用Spring Boot开发实质上也是一个常规的Spring项目开发;
(2)只是利用了Spring Boot启动程序和自动配置简化开发过程,提高开发效率;
(3)Spring boot项目开发代码的实现依然是使用Spring mvc + spring + mybatis 等,当然能集成几乎所有的开源项目;
(4)采用Spring boot开发,需要掌握大量的注解,所以日常开发中注意对注解的积累;