mybatis-plus和hibernate 忽略映射字段

祁星阑
2023-12-01
  • hibernate 忽略映射字段 @Transient
import org.springframework.data.annotation.Transient;
 
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
 
@Entity
@Table(name = "t_student")
public class Student {
 
    @Id
    @GeneratedValue
    private Long id;
    @Transient 					//忽略数据库字段,不映射数据库表字段   
    private String password;
    
    private Integer age;
 
    @Transient 					//忽略数据库字段,不映射数据库表字段
    public Integer getAge() {
        return age;
    }
 
    public void setAge(Integer age) {
        this.age = age;
    }
}
  • mybatis-plus忽略映射字段 @TableField(exist = false)
@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@TableName("ls_emp_info")
public class EmpInfo implements Serializable {
 	@Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "c_id")
    private Integer cid;       
 
    @Column(name = "c_name")
    @TableField(value = "c_name")
    private String cameraName;      
    @Column(name = "c_brand")
    @TableField(value = "c_brand")
    private String cameraBrand;     
 
    @ManyToMany
    @JoinTable(
            name = "Camera_User",
            joinColumns = @JoinColumn(name = "cid"),
            inverseJoinColumns = @JoinColumn(name = "uid")
    )
    @TableField(exist = false)
    private List<User> cameraUser;  	// 不映射数据库表字段      
	@TableField(exist = false) 			// 不映射数据库表字段
	private String postMutex;
	@TableField(exist = true) 			// 映射数据库表字段
	private String postName;
}




 类似资料: