1.1 lombok 详细使用可以看官网:https://projectlombok.org/features/all
1.2 使用@Data注解,这个注解的作用是:
@Data
All together now: A shortcut for @ToString
, @EqualsAndHashCode
, @Getter
on all fields, and @Setter
on all non-final fields, and @RequiredArgsConstructor
!
1.3 修改我们的domain.Company代码如下:这里已经不必谢getter/setter方法
package com.leilei.springbootcrm.domain; import lombok.Data; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; import java.io.Serializable; import java.util.Date; @Entity @Data public class Company implements Serializable { private static final long serialVersionUID = 7471779949543151367L; @GeneratedValue @Id private Integer id; @Column(length = 50, nullable = false) private String CompanyName; private Date createTime; }
1.4 在上一篇 CompanyDaoTest追加一个测试用例,
@Test void testFindAll() { List<Company> companyList = companyDao.findAll(); System.out.println(companyList); }
1.5查看控制台打印,发现我们的toString()方法已经被重写