zoukankan      html  css  js  c++  java
  • 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);
        }
    }
  • 相关阅读:
    重构之重新组织函数(ExTract Method)
    设计模式之桥接模式
    设计模式原则之里氏替换原则
    设计模式原则之依赖倒置原则
    设计模式原则之接口隔离原则
    设计模式原则之单一职责原则
    编译php5.6
    wireshark总结
    Blu-Ray BRRip 和 BDRip 的区别
    openwrt虚拟机的network unreachable
  • 原文地址:https://www.cnblogs.com/qinls/p/9909641.html
Copyright © 2011-2022 走看看