Răsfoiți Sursa

20230723(02)-添加web接口demo

iaun 3 ani în urmă
părinte
comite
6e0766aad0

+ 25 - 0
src/main/java/cn/iaun/it/controller/ItUserController.java

@@ -0,0 +1,25 @@
+package cn.iaun.it.controller;
+
+import cn.iaun.it.model.ItUser;
+import cn.iaun.it.service.ItUserService;
+import cn.iaun.it.util.Result;
+import cn.iaun.it.util.ResultCode;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import java.util.List;
+
+@RestController
+@RequestMapping("/user")
+public class ItUserController {
+    private final ItUserService itUserService;
+
+    public ItUserController(ItUserService itUserService) {
+        this.itUserService = itUserService;
+    }
+
+    @RequestMapping(value = "/get")
+    public Result<List<ItUser>> getUser() {
+        return new Result<>(ResultCode.SUCCESS, itUserService.getAll());
+    }
+}

+ 2 - 0
src/main/java/cn/iaun/it/model/ItUser.java

@@ -1,6 +1,7 @@
 package cn.iaun.it.model;
 package cn.iaun.it.model;
 
 
 import com.baomidou.mybatisplus.annotation.IdType;
 import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.annotation.TableId;
 import com.baomidou.mybatisplus.annotation.TableId;
 
 
 
 
@@ -9,6 +10,7 @@ public class ItUser {
     private Long userId;
     private Long userId;
     private String user;
     private String user;
     private String displayName;
     private String displayName;
+    @TableField(select = false)
     private String password;
     private String password;
     private String phoneNumber;
     private String phoneNumber;
     private Long roleId;
     private Long roleId;

+ 7 - 1
src/main/java/cn/iaun/it/service/ItUserService.java

@@ -1,4 +1,10 @@
 package cn.iaun.it.service;
 package cn.iaun.it.service;
 
 
-public class ItUserService {
+import cn.iaun.it.model.ItUser;
+
+import java.util.List;
+
+
+public interface ItUserService {
+    List<ItUser> getAll();
 }
 }

+ 19 - 1
src/main/java/cn/iaun/it/service/impl/ItUserServiceImpl.java

@@ -1,4 +1,22 @@
 package cn.iaun.it.service.impl;
 package cn.iaun.it.service.impl;
 
 
-public class ItUserServiceImpl {
+import cn.iaun.it.mapper.ItUserMapper;
+import cn.iaun.it.model.ItUser;
+import cn.iaun.it.service.ItUserService;
+import org.springframework.stereotype.Service;
+
+import java.util.List;
+
+@Service
+public class ItUserServiceImpl implements ItUserService {
+    private final ItUserMapper itUserMapper;
+
+    public ItUserServiceImpl(ItUserMapper itUserMapper) {
+        this.itUserMapper = itUserMapper;
+    }
+
+    @Override
+    public List<ItUser> getAll() {
+        return itUserMapper.selectList(null);
+    }
 }
 }

+ 33 - 0
src/main/java/cn/iaun/it/util/Result.java

@@ -0,0 +1,33 @@
+package cn.iaun.it.util;
+
+public class Result<T> {
+    private final Integer code;
+    private final String message;
+
+    private final T data;
+
+    public Result() {
+        this.code = 1;
+        this.message = "OK";
+        this.data = null;
+    }
+
+    public Result(ResultCode resultCode, T data) {
+        this.code = resultCode.getCode();
+        this.message = resultCode.getMessage();
+        this.data = data;
+    }
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+}

+ 21 - 0
src/main/java/cn/iaun/it/util/ResultCode.java

@@ -0,0 +1,21 @@
+package cn.iaun.it.util;
+
+public enum ResultCode {
+    SUCCESS(1, "成功");
+
+    private final Integer code;
+    private final String message;
+
+    ResultCode(Integer code, String message) {
+        this.code = code;
+        this.message = message;
+    }
+
+    public Integer getCode() {
+        return code;
+    }
+
+    public String getMessage() {
+        return message;
+    }
+}

+ 3 - 0
src/main/resources/db/data.sql

@@ -2,6 +2,9 @@ delete
 from `it_user`;
 from `it_user`;
 insert into `it_user` (`user`, `display_name`, `password`, `phone_number`, `role_id`)
 insert into `it_user` (`user`, `display_name`, `password`, `phone_number`, `role_id`)
 values ('test01', '测试01', '123456', '13012345678', 1);
 values ('test01', '测试01', '123456', '13012345678', 1);
+insert into `it_user` (`user`, `display_name`, `password`, `phone_number`, `role_id`)
+values ('test02', '测试02', '789456', '13012345678', 2);
+
 
 
 
 
 delete
 delete

+ 2 - 11
src/main/resources/db/schema.sql

@@ -6,24 +6,15 @@ CREATE TABLE `it_user`
     `display_name` VARCHAR(255) NOT NULL COMMENT '显示名称',
     `display_name` VARCHAR(255) NOT NULL COMMENT '显示名称',
     `password`     VARCHAR(255) NOT NULL COMMENT '密码',
     `password`     VARCHAR(255) NOT NULL COMMENT '密码',
     `phone_number` VARCHAR(255) NOT NULL COMMENT '手机号码',
     `phone_number` VARCHAR(255) NOT NULL COMMENT '手机号码',
-    `role_id`      BIGINT       NOT NULL DEFAULT 0 COMMENT '角色ID',
+    `role_id`      BIGINT(20)   NOT NULL DEFAULT 0 COMMENT '角色ID',
     PRIMARY KEY (`user_id`)
     PRIMARY KEY (`user_id`)
 ) COMMENT ='用户表';
 ) COMMENT ='用户表';
 
 
-drop table if exists it_permission;
-# CREATE TABLE `it_permission`
-# (
-#     `permission_id` BIGINT       NOT NULL AUTO_INCREMENT COMMENT '权限ID',
-#     `name`          VARCHAR(255) NOT NULL COMMENT '权限名称',
-#     `permissions`   VARCHAR(255) NOT NULL COMMENT '权限',
-#     PRIMARY KEY (`permission_id`)
-# ) COMMENT ='权限表';
-
 
 
 drop table if exists it_role;
 drop table if exists it_role;
 CREATE TABLE `it_role`
 CREATE TABLE `it_role`
 (
 (
-    `role_id` BIGINT       NOT NULL COMMENT '角色ID',
+    `role_id` BIGINT(20)   NOT NULL COMMENT '角色ID',
     `name`    VARCHAR(255) NOT NULL COMMENT '角色名称',
     `name`    VARCHAR(255) NOT NULL COMMENT '角色名称',
     PRIMARY KEY (`role_id`)
     PRIMARY KEY (`role_id`)
 ) COMMENT ='角色表';
 ) COMMENT ='角色表';