常用注解
常用注解
//读取yaml中的配置注入到实体类
@ConfigurationProperties(prefix="student")
public class Student { ...属性需要和yaml中名称对应,支持松散语法,yaml中使用mz-name对应java中的驼峰mzName }
//指定字段注入值
@Value("name")
private String name;
//扫描当前类注入
@Component
//JSR303校验(使用JSR303需要引入依赖)
@Validated //定义类上
//具体字段注解验证参考:https://www.jianshu.com/p/554533f88370
<!--JSR303依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>

浙公网安备 33010602011771号