摘要: SpringBoot常用注解 @SpringBootApplication @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited @Configuration @EnableAutoConfiguration @C 阅读全文
posted @ 2023-05-08 11:48 leepandar 阅读(37) 评论(0) 推荐(0) 编辑
摘要: SpringBoot运行流程 一、准备阶段 我们先看一下这个SpringApplication的构造方法中做了什么事情,为run方法准备了那些事情 通常在一个spring boot的应用中,会看到下面一段代码作为应用的入口 @SpringBootApplication public class Application { pub 阅读全文
posted @ 2023-05-08 10:25 leepandar 阅读(504) 评论(0) 推荐(0) 编辑
摘要: SpringBoot自动配置原理 一、什么是Spring Boot的自动配置? Spring Boot的最大的特点就是简化了各种xml配置内容,还记得曾经使用SSM框架时我们在spring-mybatis.xml配置了多少内容吗?数据源、连接池、会话工厂、事务管理···,而现在Spring Boot告诉你这些都不需要了,一切交给它的 阅读全文
posted @ 2023-05-08 10:23 leepandar 阅读(135) 评论(0) 推荐(0) 编辑
摘要: SpringBoot-start机制 start机制 传统的Spring项目开发,需要导入大量的依赖,同时还需要对各种XML配置文件进行配置,过程十分繁琐。而Spring Boot项目创建完成后,即使不编写任何代码,不用进行任何配置也能运行。这些都要归功于Spring Boot的Start机制。 在没有 starter 之前,假如我想要 阅读全文
posted @ 2023-05-08 10:22 leepandar 阅读(80) 评论(0) 推荐(0) 编辑
摘要: SpringBoot定制Banner 什么是Banner 我们在启动Spring Boot程序时,有如下Banner信息: . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| 阅读全文
posted @ 2023-05-08 10:20 leepandar 阅读(49) 评论(0) 推荐(0) 编辑
摘要: SpringBoot添加日志 前言 Spring Boot使用Apache Commons日志记录进行所有内部日志记录。Spring Boot的默认配置支持使用Java Util Logging,Log4j2和Logback。 使用这些,可以配置控制台日志记录以及文件日志记录。 如果使用的是Spring Boot Starter 阅读全文
posted @ 2023-05-08 10:19 leepandar 阅读(635) 评论(0) 推荐(0) 编辑
摘要: SpringBoot统一异常处理 概述 Spring在3.2版本增加了一个注解@ControllerAdvice,可以与@ExceptionHandler、@InitBinder、@ModelAttribute 等注解注解配套使用。 简单的说,该注解可以把异常处理器应用到所有控制器,而不是单个控制器。借助该注解,我们可以实现:在独立 阅读全文
posted @ 2023-05-08 10:18 leepandar 阅读(2004) 评论(0) 推荐(1) 编辑
摘要: SpringBoot参数校验 为什么需要参数校验 在日常的接口开发中,为了防止非法参数对业务造成影响,经常需要对接口的参数进行校验,例如登录的时候需要校验用户名和密码是否为空,添加用户的时候校验用户邮箱地址、手机号码格式是否正确。 靠代码对接口参数一个个校验的话就太繁琐了,代码可读性极差。 @RestController @Re 阅读全文
posted @ 2023-05-08 10:16 leepandar 阅读(74) 评论(0) 推荐(0) 编辑
摘要: SpringBoot版本接口 前言 为什么接口会出现多个版本 一般来说,Restful API接口是提供给其它模块,系统或是其他公司使用,不能随意频繁的变更。然而,需求和业务不断变化,接口和参数也会发生相应的变化。如果直接对原来的接口进行修改,势必会影响线其他系统的正常运行。这就必须对api 接口进行有效的版本控制。 控制接口多 阅读全文
posted @ 2023-05-08 10:15 leepandar 阅读(41) 评论(0) 推荐(0) 编辑
摘要: SpringBoot访问外部接口 原生的Http请求 @RequestMapping("/doPostGetJson") public String doPostGetJson() throws ParseException { //此处将要发送的数据转换为json格式字符串 String jsonText = "{id: 1}"; 阅读全文
posted @ 2023-05-08 09:38 leepandar 阅读(45) 评论(0) 推荐(0) 编辑