¶Ô±ÈÐÂÎļþ |
| | |
| | | package com.ruoyi.web.controller.tool; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import org.springframework.web.bind.annotation.DeleteMapping; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.PutMapping; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.RestController; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.AjaxResult; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | | /** |
| | | * swagger ç¨æ·æµè¯æ¹æ³ |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Api("ç¨æ·ä¿¡æ¯ç®¡ç") |
| | | @RestController |
| | | @RequestMapping("/test/user") |
| | | public class TestController extends BaseController |
| | | { |
| | | private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>(); |
| | | { |
| | | users.put(1, new UserEntity(1, "admin", "admin123", "15888888888")); |
| | | users.put(2, new UserEntity(2, "ry", "admin123", "15666666666")); |
| | | } |
| | | |
| | | @ApiOperation("è·åç¨æ·å表") |
| | | @GetMapping("/list") |
| | | public AjaxResult userList() |
| | | { |
| | | List<UserEntity> userList = new ArrayList<UserEntity>(users.values()); |
| | | return AjaxResult.success(userList); |
| | | } |
| | | |
| | | @ApiOperation("è·åç¨æ·è¯¦ç»") |
| | | @ApiImplicitParam(name = "userId", value = "ç¨æ·ID", required = true, dataType = "int", paramType = "path") |
| | | @GetMapping("/{userId}") |
| | | public AjaxResult getUser(@PathVariable Integer userId) |
| | | { |
| | | if (!users.isEmpty() && users.containsKey(userId)) |
| | | { |
| | | return AjaxResult.success(users.get(userId)); |
| | | } |
| | | else |
| | | { |
| | | return AjaxResult.error("ç¨æ·ä¸åå¨"); |
| | | } |
| | | } |
| | | |
| | | @ApiOperation("æ°å¢ç¨æ·") |
| | | @ApiImplicitParam(name = "userEntity", value = "æ°å¢ç¨æ·ä¿¡æ¯", dataType = "UserEntity") |
| | | @PostMapping("/save") |
| | | public AjaxResult save(UserEntity user) |
| | | { |
| | | if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) |
| | | { |
| | | return AjaxResult.error("ç¨æ·IDä¸è½ä¸ºç©º"); |
| | | } |
| | | return AjaxResult.success(users.put(user.getUserId(), user)); |
| | | } |
| | | |
| | | @ApiOperation("æ´æ°ç¨æ·") |
| | | @ApiImplicitParam(name = "userEntity", value = "æ°å¢ç¨æ·ä¿¡æ¯", dataType = "UserEntity") |
| | | @PutMapping("/update") |
| | | public AjaxResult update(UserEntity user) |
| | | { |
| | | if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId())) |
| | | { |
| | | return AjaxResult.error("ç¨æ·IDä¸è½ä¸ºç©º"); |
| | | } |
| | | if (users.isEmpty() || !users.containsKey(user.getUserId())) |
| | | { |
| | | return AjaxResult.error("ç¨æ·ä¸åå¨"); |
| | | } |
| | | users.remove(user.getUserId()); |
| | | return AjaxResult.success(users.put(user.getUserId(), user)); |
| | | } |
| | | |
| | | @ApiOperation("å é¤ç¨æ·ä¿¡æ¯") |
| | | @ApiImplicitParam(name = "userId", value = "ç¨æ·ID", required = true, dataType = "int", paramType = "path") |
| | | @DeleteMapping("/{userId}") |
| | | public AjaxResult delete(@PathVariable Integer userId) |
| | | { |
| | | if (!users.isEmpty() && users.containsKey(userId)) |
| | | { |
| | | users.remove(userId); |
| | | return AjaxResult.success(); |
| | | } |
| | | else |
| | | { |
| | | return AjaxResult.error("ç¨æ·ä¸åå¨"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @ApiModel("ç¨æ·å®ä½") |
| | | class UserEntity |
| | | { |
| | | @ApiModelProperty("ç¨æ·ID") |
| | | private Integer userId; |
| | | |
| | | @ApiModelProperty("ç¨æ·åç§°") |
| | | private String username; |
| | | |
| | | @ApiModelProperty("ç¨æ·å¯ç ") |
| | | private String password; |
| | | |
| | | @ApiModelProperty("ç¨æ·ææº") |
| | | private String mobile; |
| | | |
| | | public UserEntity() |
| | | { |
| | | |
| | | } |
| | | |
| | | public UserEntity(Integer userId, String username, String password, String mobile) |
| | | { |
| | | this.userId = userId; |
| | | this.username = username; |
| | | this.password = password; |
| | | this.mobile = mobile; |
| | | } |
| | | |
| | | public Integer getUserId() |
| | | { |
| | | return userId; |
| | | } |
| | | |
| | | public void setUserId(Integer userId) |
| | | { |
| | | this.userId = userId; |
| | | } |
| | | |
| | | public String getUsername() |
| | | { |
| | | return username; |
| | | } |
| | | |
| | | public void setUsername(String username) |
| | | { |
| | | this.username = username; |
| | | } |
| | | |
| | | public String getPassword() |
| | | { |
| | | return password; |
| | | } |
| | | |
| | | public void setPassword(String password) |
| | | { |
| | | this.password = password; |
| | | } |
| | | |
| | | public String getMobile() |
| | | { |
| | | return mobile; |
| | | } |
| | | |
| | | public void setMobile(String mobile) |
| | | { |
| | | this.mobile = mobile; |
| | | } |
| | | } |