V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
hidemyself
V2EX  ›  问与答

请问一下各位, Mybatis 怎么处理 复合类型的数组

  •  
  •   hidemyself · Sep 13, 2021 · 1048 views
    This topic created in 1698 days ago, the information mentioned may be changed or developed.

    数据库是 postgresql,后端 java 比如

    CREATE TYPE inventory_item AS (
        name            text,
        supplier_id     integer,
        price           numeric
    );
    
    CREATE TABLE on_hand (
        item      inventory_item[]
    )
    

    mybatis 应该怎么处理 on_hand 中的 item 字段呢? 我尝试用 object[],但是做插入操作的时候会报错。 尝试用 string[],插入不报错了,但是获取返回值的时候会报错 请问各位有没有解决办法。 查了半天,就查不到多少 mybatis+postgresql 这种组合的。。

    3 replies    2021-09-14 16:00:28 +08:00
    itechify
        1
    itechify  
    PRO
       Sep 13, 2021 via Android
    mybatis plus 的话,看看这个?

    https://baomidou.com/guide/typehandler.html

    其他基于 mybatis 的库类似的原理
    frankly123
        2
    frankly123  
       Sep 14, 2021
    实现个 TypeHandler 吧
    hidemyself
        3
    hidemyself  
    OP
       Sep 14, 2021
    @frankly123 嗯嗯,魔改了一下那个 ArrayTypeHanlder,现在可以了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   4564 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 44ms · UTC 10:06 · PVG 18:06 · LAX 03:06 · JFK 06:06
    ♥ Do have faith in what you're doing.