2018-06-29 14:38:57 1397瀏覽
在目前大多數(shù)程序開發(fā)中都會(huì)使用到框架,比如Java培訓(xùn)中SpringBoot是非常高效的開發(fā)框架,lombok是一套代碼模板解決方案,將極大提升開發(fā)的效率,這里介紹給大家使用。<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency>
>>2.切到lombok下載的目錄,運(yùn)行命令:java-jarlombok.jar
選中目錄之后,就會(huì)看到如下窗口:
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默認(rèn)反射對(duì)象中的所有屬性,非常的好用。以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望多多關(guān)注扣丁學(xué)堂。
【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】
查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>