V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐工具
RoboMongo
推荐书目
50 Tips and Tricks for MongoDB Developers
Related Blogs
Snail in a Turtleneck
aoscici2000
V2EX  ›  MongoDB

spring 中使用 mongodb, 库存表一般怎么设计和返回

  •  
  •   aoscici2000 · May 14, 2019 · 4052 views
    This topic created in 2540 days ago, the information mentioned may be changed or developed.

    "store": [ { "label": "S", "store": 100 }, { "label": "M", "store": 100 }, { "label": "L", "store": 100 } ]

    比如表里的数据结构写成了这样, @Field private List<object> store;

    查询到是没问题, 但写回的数据是空的?
    

    一般这类有字符串和数字混合的是怎么设计的?

    </object>

    3 replies    2019-05-17 09:42:34 +08:00
    xyooyx
        1
    xyooyx  
       May 14, 2019 via iPhone   ❤️ 1
    ✔️google
    ✖️v2 等回复
    460881773
        2
    460881773  
       May 15, 2019   ❤️ 1
    直接用 fastjson 的 jsonarray 就可以。 其他 json 会有_class 字段很恶心。 如果不想用,可以定为 @Field(value = "store")
    private List<HashMap<String, Object>> store;
    thinkmore
        3
    thinkmore  
       May 17, 2019
    ```java
    List<Store> store;

    class store {
    String label;
    Integer store;
    }
    ```

    难道不是这样吗?
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3200 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 13:39 · PVG 21:39 · LAX 06:39 · JFK 09:39
    ♥ Do have faith in what you're doing.