美文网首页spring
采用注解方式开发bean

采用注解方式开发bean

作者: tmac09 | 来源:发表于2019-03-05 10:27 被阅读0次

创建一个Hello类,采用@Component注解

HelloApp类,采用@ComponentScan注解

运行结果

2.Student和Phone的例子改成注解实现

Lombok插件的使用

File->Settings->plugins,搜索Lombok,安装,重启IDEA

添加依赖

使用@Data注解,简化POJO类,不用再写那些构造方法、getter/setter,toString()了,专注定义属性。

Student类

Phone类

StudentApp类

运行结果

注释

@Data

@Setter

@Getter

@Log4j

@AllArgsConstructor

@NoArgsConstructor

@EqualsAndHashCode

@NonNull

@Cleanup

@ToString

@RequiredArgsConstructor

@Value

@SneakyThrows

@Synchronized

相关文章

网友评论

    本文标题:采用注解方式开发bean

    本文链接:https://www.haomeiwen.com/subject/pxcnuqtx.html