Mybatis之Lombok插件
程序员文章站
2022-03-26 17:13:36
通过在IDEA安装Lombok插件,在实体类上增加注解来实现有参、无参构造、tostring等,简化代码1、导入依赖 org.projectlombok lombok
通过在IDEA安装Lombok插件,在实体类上增加注解来实现有参、无参构造、tostring等,简化代码
1、导入依赖
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
2、注解类型
@Getter and @Setter
@FieldNameConstants
@ToString
@EqualsAndHashCode
@AllArgsConstructor, @RequiredArgsConstructor and @NoArgsConstructor
@Log, @Log4j, @Log4j2, @Slf4j, @XSlf4j, @CommonsLog, @JBossLog, @Flogger, @CustomLog
@Data
@Builder
@SuperBuilder
@Singular
@Delegate
@Value
@Accessors
@Wither
@With
@SneakyThrows
@val
@var
experimental @var
@UtilityClass
3、在实体类上增加注解
下面是没增加前:
package com.lizheng.pojo;
import org.apache.ibatis.type.Alias;
/**
* User实体类:数据库连接对象
* @author 李争
*/
@Alias("User")//给实体类起别名
public class User {
private int id ;
private String name;
private String password;
public User() {
}
public User(int id, String name, String password) {
this.id = id;
this.name = name;
this.password = password;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPwd() {
return password;
}
public void setPwd(String pwd) {
this.password = password;
}
@Override
public String toString() {
return "User{" +
"id=" + id +
", name='" + name + '\'' +
", pwd='" + password + '\'' +
'}';
}
}
增加注解:
@Alias("User")//给实体类起别名
@Data
@AllArgsConstructor
@NoArgsConstructor
public class User {
private int id ;
private String name;
private String password;
}
查看类结构器:
本文地址:https://blog.csdn.net/qq_38723455/article/details/112253202
上一篇: 矩形覆盖(斐波那契)
下一篇: Fiber纤程代码实例