2018-06-29 14:38:57 457浏览
在目前大多数程序开发中都会使用到框架,比如Java培训中SpringBoot是非常高效的开发框架,lombok是一套代码模板解决方案,将极大提升开发的效率,这里介绍给大家使用。<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency>
>>2.切到lombok下载的目录,运行命令:java-jarlombok.jar
选中目录之后,就会看到如下窗口:
importlombok.Data; importlombok.extern.slf4j.Slf4j; @Slf4j @Data publicclassTestBean{ privateStringname; privateintage; }
importorg.junit.Test; importorg.junit.runner.RunWith; importorg.springframework.beans.factory.annotation.Autowired; importorg.springframework.boot.test.context.SpringBootTest; importorg.springframework.test.context.junit4.SpringRunner; importlombok.extern.slf4j.Slf4j; @RunWith(SpringRunner.class) @SpringBootTest @Slf4j publicclassTestEntityBean{ TestBeanbean=newTestBean(); @Autowired privateMyCasemycase; //@Test publicvoidtest(){ bean.setAge(123); bean.setName("zhangsan"); log.info(bean.toString()); } }
._________ /\\/___'_____(_)______\\\\ (()\___|'_|'_||'_\/_`|\\\\ \\/___)||_)|||||||(_||)))) '|____|.__|_||_|_||_\__,|//// =========|_|==============|___/=/_/_/_/ ::SpringBoot::(v1.4.1.RELEASE)
大家可以注意到@Slf4j替代掉了冗余的logger声明语句,@Data不必在使用Getter/Setter方法,其中toString默认反射对象中的所有属性,非常的好用。以上就是本文的全部内容,希望对大家的学习有所帮助,也希望多多关注扣丁学堂。
【关注微信公众号获取更多学习资料】