您的位置:首页 > 文旅 > 旅游 > 汽车之家网页版入口官网_互联网商业计划书模板范文_关键词优化的主要工具_专业百度seo排名优化

汽车之家网页版入口官网_互联网商业计划书模板范文_关键词优化的主要工具_专业百度seo排名优化

2025/7/15 18:46:22 来源:https://blog.csdn.net/goldenfish1919/article/details/142418351  浏览:    关键词:汽车之家网页版入口官网_互联网商业计划书模板范文_关键词优化的主要工具_专业百度seo排名优化
汽车之家网页版入口官网_互联网商业计划书模板范文_关键词优化的主要工具_专业百度seo排名优化

方式1:@Controller或者@RestController

/*** 方式1:@Controller* */
@RestController
public class AtController {@GetMapping("/at")public String at() {return "@Controller";}
}

方式2:@Component + Controller接口

/*** 方式2:@Component + Controller接口* */
@Component("/interface")
public class InterfaceController implements Controller {@Overridepublic ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {response.setContentType("text/html;charset=utf-8");response.getOutputStream().write("Controller implements interface".getBytes(StandardCharsets.UTF_8));return null;}
}

方式3:@Component + HttpRequestHandler

/*** 方式3:@Component + HttpRequestHandler* */
@Component("/httpRequestHandler")
public class HttpRequestHandlerController implements HttpRequestHandler {@Overridepublic void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {response.setContentType("text/html;charset=utf-8");response.getOutputStream().write("Controller implements HttpRequestHandler".getBytes(StandardCharsets.UTF_8));}
}

方式4:@Bean + RouterFunction

/*** 方式4:RouterFunction,WebFlux也有类似的方式* */@Beanpublic RouterFunction routerFunction(){return RouterFunctions.route().GET("/routerFunction",request-> ServerResponse.ok().contentType(MediaType.TEXT_HTML).body("Controller using RouterFunction")).build();}

知道这些方式有啥用呢?有些时候,我们需要在starter中内置一些controller,但是又不想被其他的组件扫描到(比如swagger),这个时候用处就来了。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com