One, Springboot automatic configuration principle
1. A lot of automatic configuration classes are defined in the META-INF\spring.fatories file; you can rely on automatic configuration components based on the starter added in the pom.xml file
2. Through the following process, you can modify the application configuration file and change the default parameters of the automatically configured components
eg:
Two, Lombok
Add @Data to javabean, then you can omit the writing of getter and setter methods, and the lombok plug-in will be automatically generated.
pom.xml :
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.3</version>
</parent>
<groupId>cn.itcast</groupId>
<artifactId>Spingboot_day1</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<java.version>1.9</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--java配置配置数据库要的-->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.10</version>
</dependency>
<!--Spring Boot的属性注入需要的-->
<dependency>
<groupId> org.springframework.boot </groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<!--不传递依赖-->
<optional>true</optional>
</dependency>
<!--lombok需要的-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
</dependencies>
</project>
Entity class:
package com.itheima.pojo;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import java.util.Date;
/**
* @author QLBF
* @version 1.0
* @date 2021/2/21 17:30
*/
//在编译阶段会根据注解自动生成对应的方法;data包含get/set/hashCode/equals/toString等方法
@Data
public class User {
private Long id;
private String user_name;
private String password;
private String name;
private Integer age;
private Integer sex;
private Date birthday;
private String note;
private Date created;
private Date updated;
}
You can add @Slf4j to the class to use log, such as: