Home
Sign Up
Sign In
• 请不要在回答技术问题时复制粘贴 AI 生成的内容
V2EX
›
程序员
gorm 中动态处理更新字段有什么好方法没
suroppo
·
Feb 8, 2021
· 2094 views
You need to sign in to view this topic
This topic created in 1994 days ago, the information mentioned may be changed or developed.
问题主要出在更新的字段更新为默认值, 因为 gorm 中默认是不更新 struct 的默认值的. 但又不想使用 map
gorm
默认
更新
字段
3 replies
•
2021-02-09 10:30:07 +08:00
1
996635
Feb 8, 2021
加*号
2
kiripeng
Feb 8, 2021
可以写个反射遍历的结构体,然后得出 map,这样做一次封装,就不用管 map 了,之后只调用函数就行了
3
labulaka521
Feb 9, 2021
https://gorm.io/docs/update.html#Update-Selected-Fields
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Solana
·
2952 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 26ms ·
UTC 13:15
·
PVG 21:15
·
LAX 06:15
·
JFK 09:15
♥ Do have faith in what you're doing.
❯