接口 CommonDao(公共Dao提供增删改查方法 deletes)

void deletes(java.lang.Class cls,
             java.util.List unids)
             throws java.lang.Exception

批量删除po对象类中传入的主键集合unids对应的数据.

 

参数:

cls - po对象类

unids - unid集合

抛出:

java.lang.Exception

public void deletes(Class cls,final List unids)throws Exception{
   for(int i=0;i<unids.size();i++){
       this.delete(cls, unids.get(i).toString());
   }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,我可以为您提供一个简单的示例代码: ``` package main import ( "context" "fmt" "net/http" "strconv" "github.com/gin-gonic/gin" "github.com/facebookincubator/ent" "github.com/facebookincubator/ent/dialect/sql" "github.com/facebookincubator/ent/dialect/sql/sqlgraph" "github.com/facebookincubator/ent/entc/integration/migrate" "github.com/facebookincubator/ent/entc/integration/migrate/migratetest" "github.com/facebookincubator/ent/entc/integration/migrate/testhelper" "github.com/facebookincubator/ent/schema/field" "github.com/facebookincubator/ent/schema/index" "github.com/facebookincubator/ent/schema/mixin" "github.com/facebookincubator/ent/schema/privacy" ) // User holds the schema definition for the User entity. type User struct { ent.Schema } // Fields of the User. func (User) Fields() []ent.Field { return []ent.Field{ field.String("name"), field.Int("age"), } } // Mixin of the User. func (User) Mixin() []ent.Mixin { return []ent.Mixin{ mixin.Time{}, } } // Index of the User. func (User) Indexes() []ent.Index { return []ent.Index{ // unique index. index.Fields("name").Unique(), // index for multiple fields. index.Fields("name", "age"), } } // Policy of the User. func (User) Policy() ent.Policy { return privacy.Policy{ Query: privacy.QueryPolicy{ Rules: privacy.AllowReadRule(), }, Mutation: privacy.MutationPolicy{ Rules: privacy.AllowWriteRule(), }, } } // CreateUserRequest holds the parameters for creating a new user. type CreateUserRequest struct { Name string `json:"name"` Age int `json:"age"` } // UpdateUserRequest holds the parameters for updating an existing user. type UpdateUserRequest struct { Name string `json:"name"` Age int `json:"age"` } // GetUserResponse holds the response for getting a single user. type GetUserResponse struct { ID int `json:"id"` Name string `json:"name"` Age int `json:"age"` } // CreateUser creates a new user. func CreateUser(c *gin.Context) { var req CreateUserRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } user, err := client.User. Create(). SetName(req.Name). SetAge(req.Age). Save(context.Background()) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"id": user.ID}) } // UpdateUser updates an existing user. func UpdateUser(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } var req UpdateUserRequest if err := c.ShouldBindJSON(&req); err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } user, err := client.User. Update(). Where(user.ID(id)). SetName(req.Name). SetAge(req.Age). Save(context.Background()) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"id": user.ID}) } // DeleteUser deletes an existing user. func DeleteUser(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } if err := client.User. DeleteOneID(id). Exec(context.Background()); err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } c.JSON(http.StatusOK, gin.H{"status": "success"}) } // GetUser gets a single user by ID. func GetUser(c *gin.Context) { id, err := strconv.Atoi(c.Param("id")) if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } user, err := client.User. Query(). Where(user.ID(id)). Only(context.Background()) if err != nil { c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()}) return } resp := GetUserResponse{ ID: user.ID, Name: user.Name, Age: user.Age, } c.JSON(http.StatusOK, resp) } func main() { // Create a new gin router. r := gin.Default() // Create a new ent client. client, err := ent.NewClient(ent.Driver(sqlgraph.New(sql.OpenDB("sqlite3", ":memory:"))))) if err != nil { panic(err) } defer client.Close() // Run migrations. if err := client.Schema.Create(context.Background(), migrate.WithGlobalUniqueID(true)); err != nil { panic(err) } // Setup routes. r.POST("/users", CreateUser) r.PUT("/users/:id", UpdateUser) r.DELETE("/users/:id", DeleteUser) r.GET("/users/:id", GetUser) // Start listening. if err := r.Run(":8080"); err != nil { panic(err) } } ``` 以上代码使用了 gin 和 ent 框架,提供了四个接口分别用于创建、更新、除和询用户。您可以使用 POST 请求发送 JSON 格式的数据来创建新用户,使用 PUT 请求发送 JSON 格式的数据来更新现有用户,使用 DELETE 请求除现有用户,使用 GET 请求询现有用户。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

草原印象

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值