GORM 開發例項

2021-10-06 08:48:21 字數 595 閱讀 6747

用 hql 的方式,這種方式好處是可以新增 distinct

@transactional

(readonly =

true

)@compiledynamic

collection

listvlogofallsubspecials

(int offset =0,

int max =10)

用 criteria 的方式,這種方式去重工作是拿到結果集合後在記憶體中完成的,而不是在資料庫中。

list

allsubspecials = vlogtag.

findallbysystem

(true

) def c = vlog.

createcriteria()

c.listdistinct

order "datecreated"

,"desc"

firstresult

(offset)

maxresults

(max)

} as collection

gorm使用和例項封裝

三 gorm資料庫連線例項封裝 建立 db.create product 讀取 var product product db.first product,1 查詢id為1的product db.first product,code l1212 查詢code為l1212的product 更新 更新pr...

gorm 開發架構 寫外掛程式

目錄gorm使用可鏈結的api,gorm.db是鏈的橋梁,對於每個鏈api,它將建立乙個新的關係。db,err gorm.open postgres user gorm dbname gorm sslmode disable 建立新關係 db db.where name jinzhu 過濾更多 if...

gorm快速使用

模型 為表中的字段,記得欄位名開頭大寫 type patient struct 此例為postgresql func main 不重新建立複數結尾的表,還是原來的表,可以利用原表中的結構,資料 db.singulartable true defer db.close 建立 patient db.cr...