package com.ciih.workshop.controller;
import cn.hutool.core.util.NumberUtil;
import com.ciih.workshop.task.BackUpDataBaseManager;
import com.ciih.workshop.utils.sun.AjaxJson;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.mvc.condition.PatternsRequestCondition;
import org.springframework.web.servlet.mvc.condition.RequestMethodsRequestCondition;
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
import javax.annotation.Resource;
import javax.websocket.Session;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Controller: 一个毫无业务的测试控制器。。。。。。
*
* @author SZW
*/
@RestController
@RequestMapping("test")
@Slf4j
public class AccAdminController extends BaseController {
@Resource
WebApplicationContext applicationContext;
@RequestMapping("/get")
public AjaxJson getUri() {
RequestMappingHandlerMapping mapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
// 获取url与类和方法的对应信息
Map<RequestMappingInfo, HandlerMethod> map = mapping.getHandlerMethods();
List<Map<String, String>> list = new ArrayList<>();
for (Map.Entry<RequestMappingInfo, HandlerMethod> m : map.entrySet()) {
Map<String, String> result = new HashMap<>();
RequestMappingInfo info = m.getKey();
HandlerMethod method = m.getValue();
PatternsRequestCondition p = info.getPatternsCondition();
for (String url : p.getPatterns()) {
result.put("url", url);
}
result.put("className", method.getMethod().getDeclaringClass().getName());
result.put("method", method.getMethod().getName());
RequestMethodsRequestCondition methodsCondition = info.getMethodsCondition();
for (RequestMethod requestMethod : methodsCondition.getMethods()) {
result.put("type", requestMethod.toString());
}
list.add(result);
}
return AjaxJson.getSuccess("扫描完毕:" + list.size(), list);
}
}
SpringBoot 接口扫描器
最新推荐文章于 2024-04-08 11:08:19 发布