SpringBoot热部署与插件Lombok

SpringBoot热部署(简单操作)

1、在pom文件中添加如下依赖和插件

<!--热部署-->
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-devtools</artifactId>
			<scope>true</scope>  <!--设置为true热部署才会起到效果-->
			<optional>true</optional>
		</dependency>
         <plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
				<configuration>
					<fork>true</fork>
				</configuration>
		</plugin>

2、修改配置文件application.properties

	#热部署生效
   	spring.devtools.restart.enabled: true
   	#设置重启的目录
   	spring.devtools.restart.additional-paths: src/main/java
   	#classpath目录下的WEB-INF文件夹内容修改不重启
   	spring.devtools.restart.exclude: WEB-INF/**

3、配置IDEA
在这里插入图片描述
Shift+Ctrl+A
在这里插入图片描述
在这里插入图片描述
最后重新启动idea就可以了

Lombok

lombok就是为了省去我们手动创建getter和setter方法,它能够在我们编译源码的时候自动帮我们生成getter和setter方法,在源码中没有getter和setter方法,但是在编译生成的文件中有getter和setter方法。

1、lombok的简单配置

1、添加maven依赖

	<!--lombok依赖-->
	<dependency>
		<groupId>org.projectlombok</groupId>
		<artifactId>lombok</artifactId>
		<optional>true</optional>
	</dependency>

2、在IDEA中下载插件
file------>setting----->Piugins
在这里插入图片描述
3、开启ombok注解在编译阶段起到作用
file------>Build,Execution,Deployment------->Annotation Processors
在这里插入图片描述
以上步骤就成功配置了lombok,我们在日常开发中就可以使用lombok了。

2、lombok常用注解的使用

1、@Setter

  //原始类
  package com.example.demo.model;
  import lombok.Setter;
  /**
  * @author
  * @description
  * @date
  */
  @Setter
  public class Student {
  	private String name;
  	private String address;
  	private String className;
  	private Long id;
  }
  //编辑后的
  package com.example.demo.model;
  public class Student {
  	private String name;
  	private String address;
 	 	private String className;
  	private Long id;
  	public Student() {}
  	public void setName(String name) {
      	this.name = name;
      }
  	public void setAddress(String address) {
      	this.address = address;
  	}
  	public void setClassName(String className) {
      	this.className = className;
 	 	}
  	public void setId(Long id) {
      	this.id = id;
  	}
  	public String getName() {
      	return this.name;
  	}
  	public String getAddress() {
      	return this.address;
  	}
  	public String getClassName() {
      	return this.className;
  	}
  	public Long getId() {
      	return this.id;
 	 	}
 	 }

2、@Getter

	//原始类
	package com.example.demo.model;
	import lombok.Setter;
	/**
 	* @author
 	* @description
 	* @date
 	*/
	@Setter
	public class Student {
    	private String name;
    	private String address;
    	private String className;
    	private Long id;
    }
    //编辑后的
	package com.example.demo.model;
	public class Student {
    	private String name;
    	private String address;
    	private String className;
    	private Long id;

    	public Student() {
    	}

    	public String getName() {
        	return this.name;
    	}

    	public String getAddress() {
        	return this.address;
   	 	}

    	public String getClassName() {
        	return this.className;
    	}

    	public Long getId() {
        	return this.id;
    	}
	}

3、@NoArgsConstructor 生成无参数构造方法
4、@AllArgsConstructor 生成全参的构造方法
5、@RequiredArgsConstructor 生成打上@NotNull注解参数的带参构造方法
这里打上@NotNull注解的参数如果是null会出现空指针异常

package com.example.demo.model;

import com.sun.istack.internal.NotNull;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.Setter;

/**
 * @author
 * @description
 * @date
 */
@Getter
@Setter
@NoArgsConstructor
@RequiredArgsConstructor
public class Student {

    private String name;
    private String address;
    private String className;
    @NotNull
    private Long id;
}

//编译后的类
package com.example.demo.model;

import com.sun.istack.internal.NotNull;

public class Student {
    private String name;
    private String address;
    private String className;
    @NotNull
    private Long id;

    public String getName() {
        return this.name;
    }

    public String getAddress() {
        return this.address;
    }

    public String getClassName() {
        return this.className;
    }

    public Long getId() {
        return this.id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public void setId(Long id) {
        if(id == null) {
            throw new NullPointerException("id is marked non-null but is null");
        } else {
            this.id = id;
        }
    }

    public Student() {
    }

    public Student(Long id) {
        if(id == null) {
            throw new NullPointerException("id is marked non-null but is null");
        } else {
            this.id = id;
        }
    }
}

6、@ToString 生成所有属性的toString()方法
7、@EqualsAndHashCode 生成equals()方法和hashCode方法
8、@Data =@Setter+@Getter+@EqualsAndHashCode+@NoArgsConstructor

package com.example.demo.model;
import lombok.Data;
/**
 * @author
 * @description
 * @date
 */
@Data
public class Student {

    private String name;
    private String address;
    private String className;
    private Long id;
}

//编译后的类
package com.example.demo.model;

public class Student {
    private String name;
    private String address;
    private String className;
    private Long id;

    public Student() {
    }

    public String getName() {
        return this.name;
    }

    public String getAddress() {
        return this.address;
    }

    public String getClassName() {
        return this.className;
    }

    public Long getId() {
        return this.id;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public void setClassName(String className) {
        this.className = className;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public boolean equals(Object o) {
        if(o == this) {
            return true;
        } else if(!(o instanceof Student)) {
            return false;
        } else {
            Student other = (Student)o;
            if(!other.canEqual(this)) {
                return false;
            } else {
                label59: {
                    String this$name = this.getName();
                    String other$name = other.getName();
                    if(this$name == null) {
                        if(other$name == null) {
                            break label59;
                        }
                    } else if(this$name.equals(other$name)) {
                        break label59;
                    }

                    return false;
                }

                String this$address = this.getAddress();
                String other$address = other.getAddress();
                if(this$address == null) {
                    if(other$address != null) {
                        return false;
                    }
                } else if(!this$address.equals(other$address)) {
                    return false;
                }

                String this$className = this.getClassName();
                String other$className = other.getClassName();
                if(this$className == null) {
                    if(other$className != null) {
                        return false;
                    }
                } else if(!this$className.equals(other$className)) {
                    return false;
                }

                Long this$id = this.getId();
                Long other$id = other.getId();
                if(this$id == null) {
                    if(other$id != null) {
                        return false;
                    }
                } else if(!this$id.equals(other$id)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(Object other) {
        return other instanceof Student;
    }

    public int hashCode() {
        boolean PRIME = true;
        byte result = 1;
        String $name = this.getName();
        int result1 = result * 59 + ($name == null?43:$name.hashCode());
        String $address = this.getAddress();
        result1 = result1 * 59 + ($address == null?43:$address.hashCode());
        String $className = this.getClassName();
        result1 = result1 * 59 + ($className == null?43:$className.hashCode());
        Long $id = this.getId();
        result1 = result1 * 59 + ($id == null?43:$id.hashCode());
        return result1;
    }

    public String toString() {
        return "Student(name=" + this.getName() + ", address=" + this.getAddress() + ", className=" + this.getClassName() + ", id=" + this.getId() + ")";
    }
}

以上生成的方法默认都是公共的,可以通过 @Setter(AccessLevel.PRIVATE)类似的注解设置方法的作用欲
9、@Builder
打上这个注解的pojo会在编译是生成一个方法

public static Student.StudentBuilder builder() {
        return new Student.StudentBuilder();
    }

创建对象可以使用

Student student = Student.builder().name("java").address("address").id(1).build();

以上只是为了记录个人在学习和工作中用到的知识点,会根据自己实际情况陆续更新。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值