使用lombok包可以将实类的get/set方法省略
程序员文章站
2022-03-04 14:08:15
...
1.在pom.xml文件里导入包
<!--可以不用写 get、set方法-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.4</version>
<scope>provided</scope>
</dependency>```
2。编写实体类
package entity;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.Id;
import javax.persistence.Table;
@Table(name = “userinfo”)
@Setter
@Getter
public class UserDTO{
@Id
private Integer uid;
private String username;
private Integer age;
private String sex;
private String nation;
private String motion;
private String food;
private Double consume;
private Double balance;
@Override
public String toString() {
return "UserInfo{" +
"uid=" + uid +
", username='" + username + '\'' +
", age=" + age +
", sex='" + sex + '\'' +
", nation='" + nation + '\'' +
", motion='" + motion + '\'' +
", food='" + food + '\'' +
", consume=" + consume +
", balance=" + balance +
'}';
}
}