Commit 28516662 by 袁伟铭

1.0.0

parent a49d0ead
...@@ -52,6 +52,13 @@ ...@@ -52,6 +52,13 @@
<artifactId>spring-boot-starter-test</artifactId> <artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!-- thymeleaf html模板引擎 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId> <artifactId>spring-boot-starter-data-redis</artifactId>
......
...@@ -3,38 +3,37 @@ package com.zq.api.controller; ...@@ -3,38 +3,37 @@ package com.zq.api.controller;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.zq.api.constant.ApiMethod; import com.zq.api.constant.ApiMethod;
import com.zq.api.form.ApiForm; import com.zq.api.form.ApiForm;
import com.zq.api.form.ApiResp;
import com.zq.api.service.IApiLogic; import com.zq.api.service.IApiLogic;
import com.zq.api.utils.ApiUtils; import com.zq.api.vo.MethodVo;
import com.zq.common.vo.ResultVo;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.stream.Collectors;
/** /**
* @author wilmiam * @author wilmiam
* @since 2022/1/21 17:00 * @since 2022/1/21 16:44
*/ */
@Api(tags = "方法接口") @Api(tags = "方法接口")
@Slf4j @Slf4j
@RestController @Controller
@RequiredArgsConstructor @RequiredArgsConstructor
@RequestMapping("/api") @RequestMapping("/api")
public class MethodController { public class MethodController {
@RequestMapping("/method") @RequestMapping("/method")
public ApiResp getAllMethod(@RequestParam(required = false) String service, @RequestParam(required = false) String name) { public String getAllMethod(Model model, @RequestParam(required = false) String service, @RequestParam(required = false) String name) {
List<Map<String, Object>> methodList = new ArrayList<>(); List<MethodVo> methodList = new ArrayList<>();
Method[] methods = IApiLogic.class.getMethods(); Method[] methods = IApiLogic.class.getMethods();
for (Method method : methods) { for (Method method : methods) {
Class<?>[] params = method.getParameterTypes(); Class<?>[] params = method.getParameterTypes();
...@@ -51,14 +50,17 @@ public class MethodController { ...@@ -51,14 +50,17 @@ public class MethodController {
} }
} }
Map<String, Object> data = new HashMap<>(); methodList.add(MethodVo.builder()
data.put("value", method.getName()); .name(apiMethod == null ? "" : apiMethod.value())
data.put("name", apiMethod == null ? "" : apiMethod.name()); .service(apiMethod == null ? "" : apiMethod.service())
data.put("service", apiMethod == null ? "" : apiMethod.service()); .value(method.getName())
methodList.add(data); .build());
} }
} }
return ApiUtils.toApiResp(new ApiForm(), ResultVo.success(methodList));
methodList = methodList.stream().sorted(Comparator.comparing(MethodVo::getService).reversed()).collect(Collectors.toList());
model.addAttribute("methodList", methodList);
return "mothod";
} }
} }
package com.zq.api.vo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author wilmiam
* @since 2022/1/27 12:30
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class MethodVo {
private String name;
private String service;
private String value;
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>方法列表</title>
</head>
<body>
<div>
<table border="1" cellspacing="0" style="margin: auto;text-align: center;">
<tr>
<th class="row">方法名</th>
<th class="row">所属服务</th>
<th class="row">调用方法名</th>
</tr>
<tr th:each="method : ${methodList}">
<td class="row" th:text="${method.name}"></td>
<td class="row" th:text="${method.service}"></td>
<td class="row" th:text="${method.value}"></td>
</tr>
</table>
</div>
</body>
<style>
.row {
padding: 3px 20px;
}
</style>
<script>
</script>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment