idea spring boot 使用 lombok

1.打开idea编辑工具,添加lombok插件,操作步骤如图:
a.点击file -> setting->Plugins,点击browse repositories:
idea spring boot 使用 lombok_第1张图片

添加插件:
idea spring boot 使用 lombok_第2张图片

插件安装完成后,重启idea

使用lombok开发
a.添加lombok引用:
idea spring boot 使用 lombok_第3张图片

b.编写代码:

package com.example.ylcz.entity;

import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;

/**
 * 作者 zxp
 * 创建时间 2018/10/20/020
 * 交流群 897841829
 */
@Getter
@Setter
@Slf4j
public class User {

    private String name;
    private String password;

    @Override
    public String toString() {
        return "name=" + name;
    }

    public static void main(String[] args) {
        User user = new User();
        user.setName("zhou");
        log.info(user.toString());
    }

}

源码查看:
idea spring boot 使用 lombok_第4张图片

lombok常用的注解是@Getter、@Setter、@Slf4j

lombok的优点:
1.可以减少代码编写
2.实体类更加简洁

lombok原理:
lombok会在编译后自动为实体生产get、set方法:
idea spring boot 使用 lombok_第5张图片

你可能感兴趣的:(spring,笔记)