sprinboot jpa实体支持mysql json字段配置

mysql字段

image

springboot配置

  • 依赖
compile('com.vladmihalcea:hibernate-types-52:2.4.1')
  • 实体
@Getter
@Setter
@Entity(name = "opt_log")
@TypeDef(name = "json",typeClass = JsonStringType.class)
public class OptLog {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @ApiModelProperty(value = "ID")
    private Long id;
    @ApiModelProperty(value = "用户ID")
    private Integer userId;
    @ApiModelProperty(value = "创建时间")
    private Date creatTime;
    @ApiModelProperty(value = "表ID")
    private Integer tableId;
    @ApiModelProperty(value = "表名称")
    private String tableName;
    @ApiModelProperty(value = "标题")
    private String title;
    @Type(type = "json")
    @ApiModelProperty(value = "详情")
    private JSONObject detail;

}

JSONObject 类型也可以换成自字义实体,并实现Serializable接口

image

posted @ 2023-01-07 13:34  码农记事本  阅读(363)  评论(0)    收藏  举报