|
@@ -2,6 +2,7 @@ package com.example.user.controller;
|
|
|
|
|
|
|
|
|
import com.example.user.domain.User;
|
|
|
+import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonArrayFormatVisitor;
|
|
|
import com.mongodb.client.result.DeleteResult;
|
|
|
import com.mongodb.client.result.UpdateResult;
|
|
|
import io.swagger.annotations.Api;
|
|
@@ -17,6 +18,7 @@ import org.springframework.data.mongodb.core.query.Update;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
@@ -35,10 +37,10 @@ public class UserController {
|
|
|
}
|
|
|
|
|
|
@ApiOperation("根据id删除用户")
|
|
|
- @DeleteMapping("/remove/{userIds}")
|
|
|
- public DeleteResult delete(@PathVariable String[] userIds){
|
|
|
+ @DeleteMapping("/remove/{userId}")
|
|
|
+ public DeleteResult delete(@PathVariable Long userId){
|
|
|
|
|
|
- Query query = new Query(Criteria.where("userId").is(userIds) );
|
|
|
+ Query query = new Query(Criteria.where("userId").is(userId) );
|
|
|
return mongoTemplate.remove(query,User.class);
|
|
|
}
|
|
|
|
|
@@ -96,5 +98,20 @@ public class UserController {
|
|
|
return userList;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 批量删除用户
|
|
|
+ */
|
|
|
+
|
|
|
+ @ApiOperation("批量删除用户")
|
|
|
+ @DeleteMapping("/removeIds/{userIds}")
|
|
|
+ public int deleteByIds(@PathVariable String[] userIds ){
|
|
|
+ Criteria criteria = Criteria.where("userId").in(userIds);
|
|
|
+ Query query = new Query(criteria);
|
|
|
+ DeleteResult result = mongoTemplate.remove(query,User.class,"users");
|
|
|
+ int deletedNum = (int) result.getDeletedCount();
|
|
|
+ return deletedNum;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
|
|
|
}
|