mirror of
https://gitcode.com/flipped-aurora/gin-vue-admin.git
synced 2026-05-24 08:07:58 +00:00
增加了前端api模板
This commit is contained in:
118
QMPlusServer/autoCode/te/autocode/api/api.go
Normal file
118
QMPlusServer/autoCode/te/autocode/api/api.go
Normal file
@@ -0,0 +1,118 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"gin-vue-admin/controller/servers"
|
||||
"gin-vue-admin/model/modelInterface"
|
||||
// 请自行引入model路径
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
|
||||
// @Tags Test
|
||||
// @Summary 创建Test
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.Test true "创建Test"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /t/createTest [post]
|
||||
func CreateTest(c *gin.Context) {
|
||||
var t autocode.Test
|
||||
_ = c.ShouldBindJSON(&t)
|
||||
err := t.CreateTest()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "创建成功", gin.H{})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags Test
|
||||
// @Summary 删除Test
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.Test true "删除Test"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
||||
// @Router /t/deleteTest [post]
|
||||
func DeleteTest(c *gin.Context) {
|
||||
var t autocode.Test
|
||||
_ = c.ShouldBindJSON(&t)
|
||||
err := t.DeleteTest()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "创建成功", gin.H{})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags Test
|
||||
// @Summary 更新Test
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.Test true "更新Test"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
||||
// @Router /t/updateTest [post]
|
||||
func UpdateTest(c *gin.Context) {
|
||||
var t autocode.Test
|
||||
_ = c.ShouldBindJSON(&t)
|
||||
err,ret := t.UpdateTest()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("更新失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "更新成功", gin.H{
|
||||
"ret":ret,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags Test
|
||||
// @Summary 用id查询Test
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body autocode.Test true "用id查询Test"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
||||
// @Router /t/findTest [post]
|
||||
func FindTest(c *gin.Context) {
|
||||
var t autocode.Test
|
||||
_ = c.ShouldBindJSON(&t)
|
||||
err,ret := t.FindById()
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("查询失败:%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "查询成功", gin.H{
|
||||
"ret":ret,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// @Tags Test
|
||||
// @Summary 分页获取Test列表
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Param data body modelInterface.PageInfo true "分页获取Test列表"
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
||||
// @Router /t/getTestList [post]
|
||||
func GetTestList(c *gin.Context) {
|
||||
var pageInfo modelInterface.PageInfo
|
||||
_ = c.ShouldBindJSON(&pageInfo)
|
||||
err, list, total := new(autocode.Test).GetInfoList(pageInfo)
|
||||
if err != nil {
|
||||
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
|
||||
} else {
|
||||
servers.ReportFormat(c, true, "获取数据成功", gin.H{
|
||||
"autocodeList": list,
|
||||
"total": total,
|
||||
"page": pageInfo.Page,
|
||||
"pageSize": pageInfo.PageSize,
|
||||
})
|
||||
}
|
||||
}
|
||||
52
QMPlusServer/autoCode/te/autocode/model/model.go
Normal file
52
QMPlusServer/autoCode/te/autocode/model/model.go
Normal file
@@ -0,0 +1,52 @@
|
||||
// 自动生成模板Test
|
||||
package autocode
|
||||
|
||||
import (
|
||||
"gin-vue-admin/controller/servers"
|
||||
"gin-vue-admin/init/qmsql"
|
||||
"gin-vue-admin/model/modelInterface"
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
type Test struct {
|
||||
gorm.Model
|
||||
TestComponent string `json:"testComponent"`
|
||||
TestBigComponent int `json:"testBigComponent"`
|
||||
}
|
||||
|
||||
// 创建Test
|
||||
func (t *Test)CreateTest()(err error){
|
||||
err = qmsql.DEFAULTDB.Create(t).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// 删除Test
|
||||
func (t *Test)DeleteTest()(err error){
|
||||
err = qmsql.DEFAULTDB.Delete(t).Error
|
||||
return err
|
||||
}
|
||||
|
||||
// 更新Test
|
||||
func (t *Test)UpdateTest()(err error, ret Test){
|
||||
err = qmsql.DEFAULTDB.Save(t).Error
|
||||
return err, *t
|
||||
}
|
||||
|
||||
// 根据ID查看单条Test
|
||||
func (t *Test)FindById()(err error,ret Test){
|
||||
err = qmsql.DEFAULTDB.Where("id = ?",t.ID).First(&ret).Error
|
||||
return err,ret
|
||||
}
|
||||
|
||||
// 分页获取Test
|
||||
func (t *Test)GetInfoList(info modelInterface.PageInfo)(err error, list interface{}, total int){
|
||||
// 封装分页方法 调用即可 传入 当前的结构体和分页信息
|
||||
err, db, total := servers.PagingServer(t, info)
|
||||
if err != nil {
|
||||
return
|
||||
} else {
|
||||
var reTestList []Test
|
||||
err = db.Find(&reTestList).Error
|
||||
return err, reTestList, total
|
||||
}
|
||||
}
|
||||
18
QMPlusServer/autoCode/te/autocode/router/router.go
Normal file
18
QMPlusServer/autoCode/te/autocode/router/router.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package router
|
||||
|
||||
import (
|
||||
"gin-vue-admin/controller/api"
|
||||
"gin-vue-admin/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func InitTestRouter(Router *gin.RouterGroup) {
|
||||
TestRouter := Router.Group("t").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
|
||||
{
|
||||
TestRouter.POST("createTest", api.CreateTest) // 新建Test
|
||||
TestRouter.POST("deleteTest", api.DeleteTest) //删除Test
|
||||
TestRouter.POST("updateTest", api.UpdateTest) //更新Test
|
||||
TestRouter.POST("findTest ", api.FindTest) // 根据ID获取Test
|
||||
TestRouter.POST("getTestList", api.GetTestList) //获取Test列表
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user