• 请不要在回答技术问题时复制粘贴 AI 生成的内容
suroppo
V2EX  ›  程序员

gorm 中动态处理更新字段有什么好方法没

  •  
  •   suroppo · Feb 8, 2021 · 1985 views
    This topic created in 1949 days ago, the information mentioned may be changed or developed.

    问题主要出在更新的字段更新为默认值, 因为 gorm 中默认是不更新 struct 的默认值的. 但又不想使用 map

    3 replies    2021-02-09 10:30:07 +08:00
    996635
        1
    996635  
       Feb 8, 2021
    加*号
    kiripeng
        2
    kiripeng  
       Feb 8, 2021
    可以写个反射遍历的结构体,然后得出 map,这样做一次封装,就不用管 map 了,之后只调用函数就行了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5665 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 64ms · UTC 03:21 · PVG 11:21 · LAX 20:21 · JFK 23:21
    ♥ Do have faith in what you're doing.