zoukankan      html  css  js  c++  java
  • spring data jpa + mysql使用json 类型

    1. 引入依赖
    <dependency>
       <groupId>com.vladmihalcea</groupId>
       <artifactId>hibernate-types-52</artifactId>
       <version>2.4.3</version>
    </dependency>
    
    1. 定义实体类
    @Data
    @Entity
    @TypeDef(name = "json", typeClass = JsonStringType.class)
    public class ExpressOrder{
        /**主键自增 */
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        private Long id;
     
        /**商品相关信息 */
        @Type(type = "json")
        @Column(columnDefinition = "json" )
        private List<CargoModel> cargoModelList;
     
        /**增值服务信息 */
        @Type(type = "json")
        @Column(columnDefinition = "json" )
        private List<AddedServiceModel> addedServiceModelList;
    }
     
    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public class CargoModel implements Serializable {
        private String name;// 货物名称
        private String count;// 货物数量
    }
     
    @Data
    @NoArgsConstructor
    @AllArgsConstructor
    public class AddedServiceModel implements Serializable {
        private String name;//增值服务名,如COD等。
        private String value;
        private String value1;
    }
    

    说明:addedServiceModelList 和cargoModelList 分别表示 表中字段added_service_model_list 和 cargo_model_list,其类型均为json

  • 相关阅读:
    85. Maximal Rectangle
    120. Triangle
    72. Edit Distance
    39. Combination Sum
    44. Wildcard Matching
    138. Copy List with Random Pointer
    91. Decode Ways
    142. Linked List Cycle II
    异或的性质及应用
    64. Minimum Path Sum
  • 原文地址:https://www.cnblogs.com/wanthune/p/12666657.html
Copyright © 2011-2022 走看看