【问题标题】:String variable in java to get and store the json array in table columnjava中的字符串变量,用于获取json数组并将其存储在表列中
【发布时间】:2018-10-16 13:52:18
【问题描述】:
json Array->
 "email_interface":["pch.hiremath@gmail.com","pch.hiremath@gmail.com"],

我需要将这些 emailIds 列表存储在表格列中,我该如何实现它。

@Column(name="email_interface", nullable=true)
    private String email_interface;

【问题讨论】:

    标签: java sql spring-boot jpa


    【解决方案1】:

    您可以将 JSON 序列化/反序列化为字符串。使用 JPA 转换器,它会自动转换。

    建议使用 Jackson JAR。

    【讨论】:

    • @Enumerated(EnumType.STRING) @Column(name="protocol", nullable=true) 私有 ProtocolTypes 协议; @Column(name="protocol_interface", nullable=true) 私有整数协议接口; @Column(name="email_interface", nullable=true) 私有字符串 email_interface;
    • 如果我更改为私有 String[] email_interface 它不起作用
    • 你可以看看这个页面。 thoughts-on-java.org/jpa-21-how-to-implement-type-converter 用于 Java ~ DB 转换器
    【解决方案2】:

    数据库支持存储此对象的数据类型 (jsonb)。 你可以参考一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-11
      • 1970-01-01
      • 1970-01-01
      • 2014-07-29
      相关资源
      最近更新 更多