zoukankan      html  css  js  c++  java
  • 关于lombok包(可使编程便捷)的一些使用

    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...");
        }
    }
  • 相关阅读:
    ToString格式化
    [转]vc中socket编程步骤
    [XAML学习资料] 验证用户提供的数据ValidationRule
    VS2008下安装boost
    [ASP.NET用户验证一]Forms验证
    VISTA IIS Worker Process 已停止工作 解决办法
    [MFC入门二]四种不同对象
    删除TFS项目
    [WPF学习资料] WPF简介
    IIS7下配置PHP5
  • 原文地址:https://www.cnblogs.com/shouyaya/p/13111289.html
Copyright © 2011-2022 走看看