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

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

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

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

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