开发指南113-BLOB等字段的处理

       访问数据库有很多中框架,千里马平台访问数据库选择了JPA(Java Persistence API)搭配Hibernate。这个框架下,如何处理BLOB这种类型的字段呢?

       处理的核心是@Lob(Large Object)注解。

       数据库字段属性为BLOB(Binary Large Object)或CLOB(Character Large Object)类型,对应JAVA类的属性为byte[]和String。

      例如如下代码:

@Data
@NoArgsConstructor
@AllArgsConstructor
@Entity
@Table(name = "sys_attach_person")
public class AttachmentEmpBO {
    @Id
    @GeneratedValue(generator="system-uuid")
    @GenericGenerator(name="system-uuid", strategy = "uuid.hex")
    @Column(name="attachment_id")
    private String attachmentId;

    @Lob
    @Column(name="file_content")
    private byte[] content;
}

仅仅多个@Lob注解,和其他字段处理模式完全相同,简直爽歪歪。

处理CLOB,定义改为String即可。

JPA架构还有很多优点,强烈推荐使用。

你可能感兴趣的:(平台开发指南,数据库)