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();
以上只是为了记录个人在学习和工作中用到的知识点,会根据自己实际情况陆续更新。