96SEO 2026-02-23 12:21 21
在gva框架下自己手动实现一个CRUD的操作该操作将会结合gen进行探讨学习具体实现可以看下面代码的实现项目目录层级分为api层service层model层common层router层gen层。

我的这个实现方式有些许不太一样就是我的修改并非传统的restful风格通过json方式进行传递这个id也确保安全所以这里的请求我不会用Get请求。
在gva下的server文件夹中找到plugin文件然后在这里创建一个banner文件夹我们的手动CRUD实现的代码就放置在这里查看项目目录结构banner包的路径是/server/plugin/banner。
在model层中我们分为前端请求的参数request以及后端返回的只response。
在我们的model下会有一个创建表的结构体也就是对应数据库字段的一个struct
github.com/flipped-aurora/gin-vue-admin/server/globaltype
gorm:column:url;comment:图片地址Path
gorm:column:path;comment:轮播图跳转地址Description
gorm:column:description;comment:轮播介绍
(github.com/flipped-aurora/gin-vue-admin/server/plugin/banner/commongithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/modelgithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/model/daogorm.io/gen
gorm:column:url;comment:图片地址Path
gorm:column:path;comment:轮播图跳转地址Description
gorm:column:description;comment:轮播介绍
gorm:column:url;comment:图片地址Path
gorm:column:path;comment:轮播图跳转地址Description
gorm:column:description;comment:轮播介绍
gorm:column:url;comment:图片地址Path
gorm:column:path;comment:轮播图跳转地址Description
gorm:column:description;comment:轮播介绍
tx.Where(dao.Banner.Url.Eq(r.Url))}if
tx.Where(dao.Banner.Path.Eq(r.Path))}if
tx.Where(dao.Banner.Description.Eq(r.Description))}return
gorm:column:url;comment:图片地址Path
gorm:column:path;comment:轮播图跳转地址Description
gorm:column:description;comment:轮播介绍
可以查看gorm的gen的使用文档地址https://gorm.io/gen/
具体详细的看gorm的文档地址关于gen的相关使用可以看目录结构我的文件存放地
gen是基于gorm封装的在我们最后的banner/main.go中需要装配一下传入db,判断有没有db没有db的调用需要传入db。
(github.com/flipped-aurora/gin-vue-admin/server/plugin/banner/modelospath/filepathgorm.io/gen
gen.WithQueryInterface,FieldCoverable:
挂在自己的结构体在这里根据自己的业务而定g.ApplyBasic(new(model.Banner),)g.Execute()
common层一般是放置一些公共资源需要使用的比如一些返回信息雪花算法生成id等。
tx.Offset(offset).Limit(c.PageSize)}
(contextgithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/commongithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/modelgithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/model/daogithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/model/requestgithub.com/pkg/errors
dao.Q.WithContext(ctx).Bannerquery
query.Scopes(info.Search())count,
query.Scopes(info.Paginate()).Find()if
dao.Q.WithContext(ctx).Bannerentity,
query.Where(dao.Banner.ID.Eq(info.ID)).First()if
dao.Q.WithContext(ctx).Bannererr
dao.Q.WithContext(ctx).Banner_,
query.Where(dao.Banner.ID.Eq(info.ID)).Updates(update)if
dao.Q.WithContext(ctx).Banner_,
query.Where(dao.Banner.ID.Eq(info.ID)).Delete()if
dao.Q.WithContext(ctx).Banner_,
query.Where(dao.Banner.ID.In(info.IDs...)).Delete()if
(github.com/flipped-aurora/gin-vue-admin/server/plugin/banner/commongithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/model/requestgithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/responsegithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/servicegithub.com/gin-gonic/ginnet/http
service.Banner.List(c.Request.Context(),
http.StatusInternalServerError,
service.Banner.First(c.Request.Context(),
http.StatusInternalServerError,
service.Banner.Create(c.Request.Context(),
http.StatusInternalServerError,
service.Banner.Update(c.Request.Context(),
http.StatusInternalServerError,
service.Banner.Delete(c.Request.Context(),
http.StatusInternalServerError,
service.Banner.Deletes(c.Request.Context(),
http.StatusInternalServerError,
(github.com/flipped-aurora/gin-vue-admin/server/middlewaregithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/apigithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/responsegithub.com/gin-gonic/gin
response.Handler()(api.Banner.List))group.POST(first,
response.Handler()(api.Banner.First))}{
带日志中间件group.Use(middleware.OperationRecord())group.POST(create,
response.Handler()(api.Banner.Create))group.PUT(update,
response.Handler()(api.Banner.Update))group.DELETE(delete,
response.Handler()(api.Banner.Delete))group.DELETE(deletes,
response.Handler()(api.Banner.Deletes))}
(github.com/flipped-aurora/gin-vue-admin/server/globalgithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/model/daogithub.com/flipped-aurora/gin-vue-admin/server/plugin/banner/routergithub.com/gin-gonic/gin
{router.NewBanner(group).Init()//
{dao.SetDefault(global.GVA_DB)}
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback