io.jboot.web.controller.annotation.RequestMapping Java Examples

The following examples show how to use io.jboot.web.controller.annotation.RequestMapping. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AddonControllerManager.java    From jpress with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void addController(Class<? extends Controller> controllerClass, String addonId) {
    RequestMapping mapping = controllerClass.getAnnotation(RequestMapping.class);
    if (mapping == null) {
        return;
    }

    String path = AnnotationUtil.get(mapping.value());
    if (path == null) {
        return;
    }

    // 尝试去清除 Controller 以保障绝对安全, 虽然插件在 stop() 的时候会去清除
    // 但是由于可能 stop() 出错等原因,没有执行到 deletController 的操作
    deleteController(controllerClass);

    String viewPath = AnnotationUtil.get(mapping.viewPath());
    if (StrUtil.isBlank(viewPath)) {
        viewPath = "/";
    } else if (viewPath.indexOf("/") != 0) {
        viewPath = "/" + viewPath;
    }

    addonRoutes.add(path, controllerClass, "/addons/" + addonId + viewPath);
    controllerAddonMapping.put(controllerClass, addonId);
}
 
Example #2
Source File: JbootSwaggerManager.java    From jboot with Apache License 2.0 5 votes vote down vote up
public void init() {
    if (!config.isConfigOk()) {
        return;
    }

    swagger = new Swagger();
    swagger.setHost(config.getHost());
    swagger.setBasePath("/");
    swagger.addScheme(HTTP);
    swagger.addScheme(HTTPS);


    Info swaggerInfo = new Info();
    swaggerInfo.setDescription(config.getDescription());
    swaggerInfo.setVersion(config.getVersion());
    swaggerInfo.setTitle(config.getTitle());
    swaggerInfo.setTermsOfService(config.getTermsOfService());

    Contact contact = new Contact();
    contact.setName(config.getContactName());
    contact.setEmail(config.getContactEmail());
    contact.setUrl(config.getContactUrl());
    swaggerInfo.setContact(contact);

    License license = new License();
    license.setName(config.getLicenseName());
    license.setUrl(config.getLicenseUrl());
    swaggerInfo.setLicense(license);


    swagger.setInfo(swaggerInfo);

    List<Class> classes = ClassScanner.scanClassByAnnotation(RequestMapping.class, false);

    Reader.read(swagger, classes);

}
 
Example #3
Source File: AddonControllerManager.java    From jpress with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void deleteController(Class<? extends Controller> c) {
    RequestMapping mapping = c.getAnnotation(RequestMapping.class);
    if (mapping == null) {
        return;
    }

    String value = AnnotationUtil.get(mapping.value());
    if (value == null) {
        return;
    }

    addonRoutes.getRouteItemList().removeIf(route -> route.getControllerKey().equals(value));
    Routes.getControllerKeySet().removeIf(actionKey -> Objects.equals(actionKey, value));
    controllerAddonMapping.remove(c);
}
 
Example #4
Source File: JbootCoreConfig.java    From jboot with Apache License 2.0 4 votes vote down vote up
@Override
public void configRoute(Routes routes) {

    routes.setMappingSuperClass(true);


    List<Class<Controller>> controllerClassList = ClassScanner.scanSubClass(Controller.class);
    if (ArrayUtil.isNotEmpty(controllerClassList)) {
        for (Class<Controller> clazz : controllerClassList) {
            RequestMapping mapping = clazz.getAnnotation(RequestMapping.class);
            if (mapping == null) {
                continue;
            }

            String value = AnnotationUtil.get(mapping.value());
            if (value == null) {
                continue;
            }

            String viewPath = AnnotationUtil.get(mapping.viewPath());

            if (StrUtil.isNotBlank(viewPath)) {
                routes.add(value, clazz, viewPath);
            } else {
                routes.add(value, clazz);
            }
        }
    }

    JbootSwaggerConfig swaggerConfig = Jboot.config(JbootSwaggerConfig.class);
    if (swaggerConfig.isConfigOk()) {
        routes.add(swaggerConfig.getPath(), JbootSwaggerController.class, swaggerConfig.getPath());
    }

    JbootAppListenerManager.me().onRouteConfig(routes);

    for (Routes.Route route : routes.getRouteItemList()) {
        JbootControllerManager.me().setMapping(route.getControllerKey(), route.getControllerClass());
    }

    routeList.addAll(routes.getRouteItemList());
}