spring-boot-starter-parent org.springframework.boot 2.5.3 org.springframework.boot spring-boot-starter-web org.projectlombok lombok
package lombok;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Generates getters for all fields, a useful toString method, and hashCode and equals implementations that check
* all non-transient fields. Will also generate setters for all non-final fields, as well as a constructor.
*
* Equivalent to {@code @Getter @Setter @RequiredArgsConstructor @ToString @EqualsAndHashCode}.
*
* Complete documentation is found at the project lombok features page for @Data.
*
* @see Getter
* @see Setter
* @see RequiredArgsConstructor
* @see ToString
* @see EqualsAndHashCode
* @see lombok.Value
/
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.SOURCE)
public @interface Data {
/*
* If you specify a static constructor name, then the generated constructor will be private, and
* instead a static factory method is created that other classes can use to create instances.
* We suggest the name: “of”, like so:
*
*
* public @Data(staticConstructor = “of”) class Point { final int x, y; }
**
* Default: No static constructor, instead the normal constructor is public.
*
* @return Name of static ‘constructor’ method to generate (blank = generate a normal constructor).
*/
String staticConstructor() default “”;
}
spring-boot-starter-parent org.springframework.boot 2.5.3 org.springframework.boot spring-boot-starter-web org.projectlombok lombok
package com.sun.springboot.bean; import lombok.Data; import org.springframework.stereotype.Component; /** * @author 孙显圣 * @version 1.0 */ @Data //getter,setter,tostring,无参构造 @Component public class Car { private String name; private Double price; }
package com.sun.springboot.bean; import lombok.Data; import org.springframework.stereotype.Component; import java.util.*; /** * @author 孙显圣 * @version 1.0 */ @Data @Component public class Monster { private Integer id; private String name; private Integer age; private Boolean isMarried; private Date birth; private Car car; private String[] skill; private Listhobby; private Map wife; private Set salaries; private Map > cars; }
package com.sun.springboot.controller; import com.sun.springboot.bean.Monster; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import javax.annotation.Resource; /** * @author 孙显圣 * @version 1.0 */ @RestController public class HiController { @Resource private Monster monster; @RequestMapping("/monster") public Monster monster() { return monster; } }
package com.sun.springboot; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @author 孙显圣 * @version 1.0 */ @SpringBootApplication public class Application { public static void main(String[] args) { SpringApplication.run(Application.class); } }
monster: #前缀 id: 100 name: 牛魔王 age: 500 isMarried: false birth: 2000/11/11
org.springframework.boot spring-boot-configuration-processor true
monster: #前缀 id: 100 name: 牛魔王 age: 500 isMarried: false birth: 2000/11/11 #对象类型 # car: {name: 宝马, price: 1000} #行内格式 car: name: 奔驰 price: 3000 #数组类型 # skill: [芭蕉扇, 牛魔拳] #行内格式 skill: - 牛魔王 - 芭蕉扇 #list类型 # hobby: [白骨精, 美人鱼] hobby: - 白骨精 - 牛魔王 #map类型 # wife: {no1: 牛魔王, no2: 猪八戒} wife: no1: 白骨精 no2: 铁扇公主 #set类型 # salaries: [1, 2, 3] salaries: - 4 - 5 - 6 #map>类型 cars: car1: [ {name: 奔驰, price: 400}, {name: 奔驰, price: 400} ] car2: [ {name: 奔驰, price: 400}, {name: 奔驰, price: 400} ] # cars: {car1: [{name: 奔驰, price: 200}, {name: 奔驰, price: 200}], # car2: [{name: 奔驰, price: 200}, {name: 奔驰, price: 200}]}