@@ -0,0 +1,37 @@
|
||||
package com.xwolf.boot.api;
|
||||
|
||||
import com.xwolf.boot.entity.User;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* [Swagger解耦]
|
||||
*/
|
||||
public interface ApiBaseController {
|
||||
@ApiOperation(value="获取用户列表", notes="")
|
||||
public List<User> getUserList();
|
||||
|
||||
@ApiOperation(value="创建用户", notes="根据User对象创建用户")
|
||||
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
|
||||
public String postUser(@RequestBody User user);
|
||||
|
||||
@ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer")
|
||||
public User getUser(@PathVariable Integer id);
|
||||
|
||||
@ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
|
||||
})
|
||||
public String putUser(@PathVariable Integer id, @RequestBody User user);
|
||||
|
||||
@ApiOperation(value="删除用户", notes="根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer")
|
||||
public String deleteUser(@PathVariable Integer id);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.xwolf.boot.api;
|
||||
|
||||
import com.xwolf.boot.entity.User;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
public interface UserBaseController {
|
||||
|
||||
public String insert(@Valid User user);
|
||||
|
||||
public List<User> getUserList(@PathVariable("start")int start, @PathVariable("size")int size);
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
package com.xwolf.boot.controller;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import com.xwolf.boot.api.ApiBaseController;
|
||||
import com.xwolf.boot.entity.User;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Swagger API测试Controller,无明确时限,以Map代替CRUD
|
||||
@@ -18,38 +18,31 @@ import java.util.*;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping(value="/api")
|
||||
public class ApiController {
|
||||
public class ApiController implements ApiBaseController {
|
||||
|
||||
private static Map<Integer, User> users = Maps.newConcurrentMap();
|
||||
|
||||
@ApiOperation(value="获取用户列表", notes="")
|
||||
@GetMapping(value={"/list"})
|
||||
@Override
|
||||
public List<User> getUserList() {
|
||||
List<User> r = new ArrayList<User>(users.values());
|
||||
return r;
|
||||
}
|
||||
|
||||
@ApiOperation(value="创建用户", notes="根据User对象创建用户")
|
||||
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
|
||||
@PostMapping(value="/add")
|
||||
@Override
|
||||
public String postUser(@RequestBody User user) {
|
||||
users.put(user.getUid(), user);
|
||||
return "success";
|
||||
}
|
||||
|
||||
@ApiOperation(value="获取用户详细信息", notes="根据url的id来获取用户详细信息")
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer")
|
||||
@RequestMapping(value="/{id}", method= RequestMethod.GET)
|
||||
@Override
|
||||
@GetMapping(value="/{id:\\d+}")
|
||||
public User getUser(@PathVariable Integer id) {
|
||||
return users.get(id);
|
||||
}
|
||||
|
||||
@ApiOperation(value="更新用户详细信息", notes="根据url的id来指定更新对象,并根据传过来的user信息来更新用户详细信息")
|
||||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer"),
|
||||
@ApiImplicitParam(name = "user", value = "用户详细实体user", required = true, dataType = "User")
|
||||
})
|
||||
@RequestMapping(value="/{id}", method=RequestMethod.PUT)
|
||||
@Override
|
||||
@PutMapping(value="/{id:\\d+}")
|
||||
public String putUser(@PathVariable Integer id, @RequestBody User user) {
|
||||
User u = users.get(id);
|
||||
u.setUname(user.getUname());
|
||||
@@ -57,14 +50,8 @@ public class ApiController {
|
||||
return "success";
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除用户
|
||||
* @param id 用户ID
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="删除用户", notes="根据url的id来指定删除对象")
|
||||
@ApiImplicitParam(name = "id", value = "用户ID", required = true, dataType = "Integer")
|
||||
@RequestMapping(value="/{id}", method=RequestMethod.DELETE)
|
||||
@Override
|
||||
@DeleteMapping(value="/{id:\\d+}")
|
||||
public String deleteUser(@PathVariable Integer id) {
|
||||
users.remove(id);
|
||||
return "success";
|
||||
|
||||
Reference in New Issue
Block a user