标签:date junit image debug rod mave 对象 pojo ctc
1.通过maven引入相关jar包依赖
<dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> </dependency>
2.需在idea上安装相应的插件lombok,添加相关的注解
3.便利性:
a.通过添加@Data注解,可使相应的实体类自动生成getter/setter/toString等方法:
package com.yzy.sell.Entity; import lombok.Data; import org.hibernate.annotations.DynamicUpdate; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; @Entity //申明是个pojo对象 @DynamicUpdate //动态更新, @Data //引入lombok包,可自动生成getter/setter/toString等方法 public class ProductCategory { @Id //设置主键 @GeneratedValue(strategy = GenerationType.IDENTITY) //自增属性,strategy表示自增策略 private Integer categoryId; private String categoryName; private Integer categoryType; public ProductCategory() { } public ProductCategory(String categoryName,Integer categoryType){ this.categoryName=categoryName; this.categoryType=categoryType; } }
b. 通过添加Slf4j,可自动生成日志对象
package com.yzy.sell; import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @RunWith (SpringRunner.class) @SpringBootTest @Slf4j public class SellApplicationTests { // private final Logger log= LoggerFactory.getLogger(SellApplicationTests.class); 使用了@Slf4j相当于生成了此对象 @Test public void test1() { String name = "yzy"; String password = "123456"; log.debug("debug..."); log.info("name: " + name + " ,password: " + password); log.info("name: {}, password: {}", name, password); log.error("error..."); log.warn("warn..."); } }
标签:date junit image debug rod mave 对象 pojo ctc
原文地址:https://www.cnblogs.com/shouyaya/p/13111289.html