1.4 引用lombak 省去bean中的 get set

1.引包

<!--加入可以省略get set 方法的插件工具-->
<dependency>
  <groupId>org.projectlombok</groupId>
  <artifactId>lombok</artifactId>
</dependency>

2.idea中安装插件

 3.实体类代码

@Entity
@DynamicUpdate  // 动态自动更新时间
@Proxy(lazy = false)  // 懒加载设置为false
@Data   // 包含了get set toString方法 也可以直接用@Getter @Setter  
public class ProductCategory { // 类目 @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer categoryId; // 类目名字 private String categoryName; // 类目编号 private Integer categoryType;
  //private Date createTime;
  //private Date updateTime;
}

4.测试

@RunWith(SpringRunner.class)
@SpringBootTest
@Slf4j
public class ProductCategoryRepositoryTest {

    @Autowired
    private ProductCategoryRepository repository;

    @Test
    public void findOneTest() {
//        ProductCategory producCategory = repository.getOne(1);

        Optional<ProductCategory> producCategory = repository.findById(1);
        log.info(producCategory.toString());
    }

    @Test
    public void saveTest(){
//        ProductCategory productCategory = new ProductCategory();
//        productCategory.setCategoryName("女生最爱");

        ProductCategory productCategory = repository.getOne(1);
        productCategory.setCategoryType(5);
        repository.save(productCategory);
    }
}
原文地址:https://www.cnblogs.com/qinls/p/9909641.html