常用注解

常用注解

//读取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>


posted @ 2021-07-03 23:35  幸运刘  阅读(26)  评论(0)    收藏  举报