{"id":710,"date":"2023-11-05T09:01:01","date_gmt":"2023-11-05T01:01:01","guid":{"rendered":""},"modified":"2023-11-05T09:01:01","modified_gmt":"2023-11-05T01:01:01","slug":"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7","status":"publish","type":"post","link":"https:\/\/mushiming.com\/710.html","title":{"rendered":"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7"},"content":{"rendered":"

\u5927\u5bb6\u597d\uff01\u6211\u662fsum\u58a8\uff0c\u4e00\u4e2a\u4e00\u7ebf\u7684\u5e95\u5c42\u7801\u519c\uff0c\u5e73\u65f6\u559c\u6b22\u7814\u7a76\u548c\u601d\u8003\u4e00\u4e9b\u6280\u672f\u76f8\u5173\u7684\u95ee\u9898\u5e76\u6574\u7406\u6210\u6587\uff0c\u9650\u4e8e\u672c\u4eba\u6c34\u5e73\uff0c\u5982\u679c\u6587\u7ae0\u548c\u4ee3\u7801\u6709\u8868\u8ff0\u4e0d\u5f53\u4e4b\u5904\uff0c\u8fd8\u8bf7\u4e0d\u541d\u8d50\u6559\u3002<\/p>\n

\u4ee5\u4e0b\u662f\u6b63\u6587\uff01<\/p>\n

\u63a5\u53e3\u6587\u6863\u662f\u4ec0\u4e48<\/h1>\n

\u63a5\u53e3\u6587\u6863\u662f\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u5b83\u63cf\u8ff0\u4e86\u7cfb\u7edf\u4e2d\u6240\u6709\u53ef\u4f9b\u5916\u90e8\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u63a5\u53e3\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u63a5\u53e3\u6587\u6863\u5c31\u662f\u7528\u6765\u5e2e\u52a9\u5f00\u53d1\u8005\u5f00\u53d1\u548c\u5bf9\u63a5\u7cfb\u7edf\u7684\u6307\u5357\u3002<\/p>\n

\u5728\u8f6f\u4ef6\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4e0d\u540c\u7684\u7cfb\u7edf\u4e4b\u95f4\u9700\u8981\u8fdb\u884c\u6570\u636e\u4ea4\u4e92\u548c\u4fe1\u606f\u4f20\u9012\uff0c\u8fd9\u5c31\u8981\u6c42\u7cfb\u7edf\u5fc5\u987b\u63d0\u4f9b\u4e00\u4e9b\u516c\u5f00\u7684\u63a5\u53e3\u3002<\/p>\n

\u63a5\u53e3\u6587\u6863\u7684\u5c55\u73b0\u5f62\u5f0f\u4e5f\u5f88\u591a\u5982\uff1aSwagger\u3001Word\u3001PDF\u3001Postman\u3001\u5f00\u653e\u5e73\u53f0\u6587\u6863\u7b49\u3002\u4e0d\u540c\u7684\u5c55\u73b0\u5f62\u5f0f\u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u8f7d\u4f53\u6765\u5448\u73b0\u63a5\u53e3\u6587\u6863\uff0c\u4f46\u662f\u6700\u7ec8\u7684\u5173\u952e\u8fd8\u662f\u5185\u5bb9\u672c\u8eab\u3002<\/p>\n

\u4e00\u4efd\u6e05\u6670\u3001\u8be6\u7ec6\u3001\u51c6\u786e\u7684\u63a5\u53e3\u6587\u6863\u662f\u5f00\u53d1\u56e2\u961f\u662f\u5426\u80fd\u591f\u51c6\u786e\u7406\u89e3\u548c\u4f7f\u7528\u7cfb\u7edf\u63a5\u53e3\u7684\u5173\u952e\u3002<\/p>\n

\u603b\u4e4b\uff0c\u4e00\u4efd\u597d\u7684\u63a5\u53e3\u6587\u6863\u5e94\u8be5\u8986\u76d6\u6240\u6709\u7684\u63a5\u53e3\u4f7f\u7528\u573a\u666f\uff0c\u8be6\u5c3d\u800c\u4e0d\u5197\u957f\uff0c\u65b9\u4fbf\u5f00\u53d1\u8005\u5feb\u901f\u67e5\u627e\u548c\u4f7f\u7528\u3002\u800c\u5bf9\u4e8e\u4e0d\u540c\u7684\u5c55\u73b0\u5f62\u5f0f\uff0c\u5f00\u53d1\u8005\u9700\u8981\u6839\u636e\u9879\u76ee\u7684\u9700\u6c42\u548c\u5f00\u53d1\u6d41\u7a0b\u9009\u62e9\u6700\u9002\u5408\u7684\u5c55\u73b0\u65b9\u5f0f\uff0c\u4ece\u800c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u5de5\u4f5c\u8d28\u91cf\u3002<\/strong><\/p>\n

Swagger\u63a5\u53e3\u6587\u6863<\/h1>\n

Swagger\u662f\u4e00\u5957\u7528\u4e8e\u8bbe\u8ba1\u3001\u6784\u5efa\u3001\u8bb0\u5f55\u548c\u4f7f\u7528RESTful API\u7684\u5de5\u5177\u96c6\uff0c\u53ef\u4ee5\u81ea\u52a8\u751f\u6210API\u6587\u6863\uff0c\u5e76\u63d0\u4f9b\u4ea4\u4e92\u5f0fUI\uff0c\u80fd\u591f\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u534f\u4f5c\u6548\u7387\u3002\u5b83\u652f\u6301\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u548c\u6846\u67b6\uff0c\u80fd\u591f\u751f\u6210\u591a\u79cd\u5c55\u73b0\u5f62\u5f0f\uff0c\u5982Swagger UI\u3001Swagger Editor\u548cSwagger Codegen\u7b49\u5de5\u5177\u3002\u540c\u65f6\uff0cSwagger\u8fd8\u63d0\u4f9b\u5f3a\u5927\u7684API\u7ba1\u7406\u529f\u80fd\uff0c\u5305\u62ecAPI\u76d1\u63a7\u3001\u8c03\u8bd5\u3001\u6d4b\u8bd5\u548c\u5b89\u5168\u6027\u7b49\uff0c\u80fd\u591f\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u7ba1\u7406\u548c\u7ef4\u62a4API\u3002<\/p>\n

\u5c55\u793a\u4e00\u4e0b<\/h2>\n

\u8bbf\u95ee\u65b9\u5f0f\u4e00<\/h3>\n

\u8bbf\u95ee\u5730\u5740\uff1ahttp:\/\/localhost:8080\/swagger-ui.html#\/<\/code><\/p>\n

\u9996\u9875<\/h4>\n

\"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7<\/p>\n

\u8be6\u60c5\u9875<\/h4>\n

\"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7<\/p>\n

\u8bbf\u95ee\u65b9\u5f0f\u4e8c<\/h3>\n

\u8bbf\u95ee\u5730\u5740\uff1ahttp:\/\/localhost:8080\/doc.html<\/code><\/p>\n

\u9996\u9875<\/h4>\n

\"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7<\/p>\n

\u4fa7\u8fb9\u680f<\/h4>\n

\"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7<\/p>\n

\u8be6\u60c5\u9875<\/h4>\n

\"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7<\/p>\n

\"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7<\/p>\n

SpringBoot\u6574\u5408Swagger2<\/h2>\n

1\u3001\u914d\u7f6e\u6587\u4ef6<\/h3>\n

SpringBoot\u9879\u76eepom.xml<\/h4>\n
<?xml version=\"1.0\"<\/span> encoding=\"UTF-8\"<\/span>?><\/span>\n<project<\/span> xmlns<\/span>=\"http:\/\/maven.apache.org\/POM\/4.0.0\"<\/span> xmlns:xsi<\/span>=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"<\/span> xsi:schemaLocation<\/span>=\"http:\/\/maven.apache.org\/POM\/4.0.0 https:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"<\/span>><\/span>\n    <modelVersion<\/span>><\/span>4.0.0<\/modelVersion<\/span>><\/span>\n    <parent<\/span>><\/span>\n        <groupId<\/span>><\/span>org.springframework.boot<\/groupId<\/span>><\/span>\n        <artifactId<\/span>><\/span>spring-boot-starter-parent<\/artifactId<\/span>><\/span>\n        <version<\/span>><\/span>2.2.6.RELEASE<\/version<\/span>><\/span>\n        <relativePath<\/span>\/><\/span> <!-- lookup parent from repository --><\/span>\n    <\/parent<\/span>><\/span>\n    <groupId<\/span>><\/span>com.example<\/groupId<\/span>><\/span>\n    <artifactId<\/span>><\/span>springboot-swagger<\/artifactId<\/span>><\/span>\n    <version<\/span>><\/span>0.0.1-SNAPSHOT<\/version<\/span>><\/span>\n    <name<\/span>><\/span>springboot-swagger<\/name<\/span>><\/span>\n    <description<\/span>><\/span>Demo project for Spring Boot<\/description<\/span>><\/span>\n    <properties<\/span>><\/span>\n        <java.version<\/span>><\/span>1.8<\/java.version<\/span>><\/span>\n    <\/properties<\/span>><\/span>\n    <dependencies<\/span>><\/span>\n        <dependency<\/span>><\/span>\n            <groupId<\/span>><\/span>org.springframework.boot<\/groupId<\/span>><\/span>\n            <artifactId<\/span>><\/span>spring-boot-starter-web<\/artifactId<\/span>><\/span>\n        <\/dependency<\/span>><\/span>\n\n        <dependency<\/span>><\/span>\n            <groupId<\/span>><\/span>org.springframework.boot<\/groupId<\/span>><\/span>\n            <artifactId<\/span>><\/span>spring-boot-starter-test<\/artifactId<\/span>><\/span>\n            <scope<\/span>><\/span>test<\/scope<\/span>><\/span>\n        <\/dependency<\/span>><\/span>\n\n        <!-- swagger --><\/span>\n        <dependency<\/span>><\/span>\n            <groupId<\/span>><\/span>io.springfox<\/groupId<\/span>><\/span>\n            <artifactId<\/span>><\/span>springfox-swagger2<\/artifactId<\/span>><\/span>\n            <version<\/span>><\/span>2.8.0<\/version<\/span>><\/span>\n        <\/dependency<\/span>><\/span>\n        <dependency<\/span>><\/span>\n            <groupId<\/span>><\/span>io.springfox<\/groupId<\/span>><\/span>\n            <artifactId<\/span>><\/span>springfox-swagger-ui<\/artifactId<\/span>><\/span>\n            <version<\/span>><\/span>2.7.0<\/version<\/span>><\/span>\n        <\/dependency<\/span>><\/span>\n        <dependency<\/span>><\/span>\n            <groupId<\/span>><\/span>com.github.xiaoymin<\/groupId<\/span>><\/span>\n            <artifactId<\/span>><\/span>swagger-bootstrap-ui<\/artifactId<\/span>><\/span>\n            <version<\/span>><\/span>1.9.2<\/version<\/span>><\/span>\n        <\/dependency<\/span>><\/span>\n    <\/dependencies<\/span>><\/span>\n\n    <build<\/span>><\/span>\n        <plugins<\/span>><\/span>\n            <plugin<\/span>><\/span>\n                <groupId<\/span>><\/span>org.springframework.boot<\/groupId<\/span>><\/span>\n                <artifactId<\/span>><\/span>spring-boot-maven-plugin<\/artifactId<\/span>><\/span>\n            <\/plugin<\/span>><\/span>\n        <\/plugins<\/span>><\/span>\n    <\/build<\/span>><\/span>\n\n<\/project<\/span>><\/span>\n<\/code><\/pre>\n

\u8fd9\u91cc\u9700\u8981\u6ce8\u610f\u4e00\u4e2a\u7248\u672c\u5bf9\u5e94\u7684\u95ee\u9898\uff0c\u5982\u679c\u4f7f\u7528\u4e86\u9ad8\u7248\u672c\u7684SpringBoot\u6846\u67b6\uff0c\u4f4e\u7248\u672c\u7684Swagger\uff0c \u4f1a\u51fa\u73b0\u5982\u4e0b\u62a5\u9519\uff1a<\/p>\n

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'<\/span>; nested exception is java.lang.NullPointerException\n\tat org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181<\/span>)\n\tat org.springframework.context.support.DefaultLifecycleProcessor.access$200<\/span>(DefaultLifecycleProcessor.java:54<\/span>)\n\tat org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:356<\/span>)\n\tat java.lang.Iterable.forEach(Iterable.java:75<\/span>)\n\tat org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:155<\/span>)\n\tat org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:123<\/span>)\n\tat org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:935<\/span>)\n\tat org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:586<\/span>)\n\tat org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145<\/span>)\n\tat org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740<\/span>)\n\tat org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415<\/span>)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:303<\/span>)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1312<\/span>)\n\tat org.springframework.boot.SpringApplication.run(SpringApplication.java:1301<\/span>)\n<\/code><\/pre>\n

\u8fd9\u662f\u56e0\u4e3a\uff1a\u56e0\u4e3aSpringfox \u4f7f\u7528\u7684\u8def\u5f84\u5339\u914d\u662f\u57fa\u4e8eAntPathMatcher\u7684\uff0c\u800cSpring Boot 2.6.X\u4f7f\u7528\u7684\u662fPathPatternMatcher\u3002<\/code><\/p>\n

\u4ee5\u4e0b\u51e0\u4e2a\u7248\u672c\u662f\u517c\u5bb9\u7684<\/strong><\/p>\n\n\n\n\n\n
SpringBoot\u7248\u672c<\/th>\nSwagger\u7248\u672c<\/th>\n<\/tr>\n<\/thead>\n
2.5.6<\/td>\n2.9.2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n\n\n\n\n\n
SpringBoot\u7248\u672c<\/th>\nSwagger\u7248\u672c<\/th>\n<\/tr>\n<\/thead>\n
2.6.5<\/td>\n3.0.0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

2\u3001\u9879\u76ee\u4ee3\u7801<\/h3>\n

\u9879\u76ee\u7ed3\u6784<\/h4>\n

\"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7<\/p>\n

SwaggerConfig.java<\/h4>\n
package<\/span> com.example.springbootswagger.config;\n\nimport<\/span> org.springframework.context.annotation.Bean;\nimport<\/span> org.springframework.context.annotation.Configuration;\nimport<\/span> springfox.documentation.builders.ApiInfoBuilder;\nimport<\/span> springfox.documentation.builders.PathSelectors;\nimport<\/span> springfox.documentation.builders.RequestHandlerSelectors;\nimport<\/span> springfox.documentation.service.ApiInfo;\nimport<\/span> springfox.documentation.service.Contact;\nimport<\/span> springfox.documentation.spi.DocumentationType;\nimport<\/span> springfox.documentation.spring.web.plugins.Docket;\n\n@Configuration<\/span>\npublic<\/span> class<\/span> SwaggerConfig<\/span> {\n\n    @Bean<\/span>\n    public<\/span> Docket createDocket<\/span>()<\/span> {\n        return<\/span> new<\/span> Docket<\/span>(DocumentationType.SWAGGER_2)\n                .apiInfo(apiInfo())\n                .enable(true<\/span>)\n                .groupName(\"\u6211\u7684\u63a5\u53e3\u6587\u6863\"<\/span>)\n                .select()\n                .apis(RequestHandlerSelectors.basePackage(\"com.example.springbootswagger.controller\"<\/span>))\n                .paths(PathSelectors.any())\n                .build();\n    }\n\n    private<\/span> ApiInfo apiInfo<\/span>()<\/span> {\n        return<\/span> new<\/span> ApiInfoBuilder<\/span>()\n                \/\/\u6807\u9898<\/span>\n                .title(\"\u51e4\u6c42\u51f0\"<\/span>)\n                \/\/\u4f5c\u8005\u3001\u94fe\u63a5\u3001\u90ae\u7bb1\u7b49<\/span>\n                .contact(new<\/span> Contact<\/span>(\n                        \"\u53f8\u9a6c\u76f8\u5982\"<\/span>,\n                        \"https:\/\/hanyu.baidu.com\/shici\/detail?pid=ecb82707a98c418995c5a0c50b770af0&from=kg0\"<\/span>,\n                        \"\"<\/span>\n                ))\n                \/\/\u63cf\u8ff0<\/span>\n                .description(\"\u6709\u4e00\u7f8e\u4eba\u516e\uff0c\u89c1\u4e4b\u4e0d\u5fd8\u3002\\n\"<\/span> +\n                        \"\u4e00\u65e5\u4e0d\u89c1\u516e\uff0c\u601d\u4e4b\u5982\u72c2\u3002\\n\"<\/span> +\n                        \"\u51e4\u98de\u7ff1\u7fd4\u516e\uff0c\u56db\u6d77\u6c42\u51f0\u3002\\n\"<\/span> +\n                        \"\u65e0\u5948\u4f73\u4eba\u516e\uff0c\u4e0d\u5728\u4e1c\u5899\u3002\\n\"<\/span> +\n                        \"\u5c06\u7434\u4ee3\u8bed\u516e\uff0c\u804a\u5199\u8877\u80a0\u3002\\n\"<\/span> +\n                        \"\u4f55\u65e5\u89c1\u8bb8\u516e\uff0c\u6170\u6211\u5f77\u5fa8\u3002\\n\"<\/span> +\n                        \"\u613f\u8a00\u914d\u5fb7\u516e\uff0c\u643a\u624b\u76f8\u5c06\u3002\\n\"<\/span> +\n                        \"\u4e0d\u5f97\u65bc\u98de\u516e\uff0c\u4f7f\u6211\u6ca6\u4ea1\u3002\\n\"<\/span> +\n                        \"\u51e4\u516e\u51e4\u516e\u5f52\u6545\u4e61\uff0c\u9068\u6e38\u56db\u6d77\u6c42\u5176\u51f0\u3002\\n\"<\/span> +\n                        \"\u65f6\u672a\u9047\u516e\u65e0\u6240\u5c06\uff0c\u4f55\u609f\u4eca\u516e\u5347\u65af\u5802\uff01\\n\"<\/span> +\n                        \"\u6709\u8273\u6dd1\u5973\u5728\u95fa\u623f\uff0c\u5ba4\u8fe9\u4eba\u9050\u6bd2\u6211\u80a0\u3002\\n\"<\/span> +\n                        \"\u4f55\u7f18\u4ea4\u9888\u4e3a\u9e33\u9e2f\uff0c\u80e1\u9889\u9883\u516e\u5171\u7ff1\u7fd4\uff01\\n\"<\/span> +\n                        \"\u51f0\u516e\u51f0\u516e\u4ece\u6211\u6816\uff0c\u5f97\u6258\u5b73\u5c3e\u6c38\u4e3a\u5983\u3002\\n\"<\/span> +\n                        \"\u4ea4\u60c5\u901a\u610f\u5fc3\u548c\u8c10\uff0c\u4e2d\u591c\u76f8\u4ece\u77e5\u8005\u8c01\uff1f\\n\"<\/span> +\n                        \"\u53cc\u7ffc\u4ff1\u8d77\u7ffb\u9ad8\u98de\uff0c\u65e0\u611f\u6211\u601d\u4f7f\u4f59\u60b2\u3002\"<\/span>)\n                \/\/\u66f4\u65b0\u8bf4\u660e<\/span>\n                .termsOfServiceUrl(\"\u8fd9\u662f\u7b2c\u4e00\u7248\"<\/span>)\n                \/\/\u7248\u672c\u53f7<\/span>\n                .version(\"1.0.0\"<\/span>).build();\n    }\n}\n<\/code><\/pre>\n

TestController.java<\/h4>\n
package<\/span> com.example.springbootswagger.controller;\n\nimport<\/span> com.example.springbootswagger.req.AddReq;\nimport<\/span> io.swagger.annotations.Api;\nimport<\/span> io.swagger.annotations.ApiImplicitParam;\nimport<\/span> io.swagger.annotations.ApiImplicitParams;\nimport<\/span> io.swagger.annotations.ApiOperation;\nimport<\/span> org.springframework.web.bind.annotation.*;\n\n@RestController<\/span>\n@Api(tags = {\"\u6d4b\u8bd5\u63a5\u53e3\u7c7b\"}, hidden = true)<\/span>\n@RequestMapping(\"\/test\")<\/span>\npublic<\/span> class<\/span> TestController<\/span> {\n\n    @ApiOperation(\"GET\u8bf7\u6c42\uff0c\u67e5\u8be2\u65b9\u6cd5\")<\/span>\n    @GetMapping(\"\/query\")<\/span>\n    public<\/span> String query<\/span>()<\/span> {\n        return<\/span> \"\u67e5\u8be2\u6210\u529f\"<\/span>;\n    }\n\n    @ApiImplicitParams({ @ApiImplicitParam(name = \"param1\", value = \"\u53c2\u65701\", required = true), @ApiImplicitParam(name = \"param2\", value = \"\u53c2\u65702\", required = false) })<\/span>\n    @ApiOperation(\"PUT\u8bf7\u6c42\uff0c\u6dfb\u52a0\u65b9\u6cd5\")<\/span>\n    @PutMapping(\"\/update\")<\/span>\n    public<\/span> String update<\/span>( @RequestParam(required = true)<\/span> String param1, @RequestParam(required = false)<\/span> String param2)<\/span> {\n        return<\/span> \"\u66f4\u65b0\u6210\u529f\"<\/span>;\n    }\n\n    @ApiOperation(\"POST\u8bf7\u6c42\uff0c\u4fee\u6539\u65b9\u6cd5\")<\/span>\n    @PostMapping(\"\/add\")<\/span>\n    public<\/span> String add<\/span>(@RequestBody<\/span> AddReq addReq)<\/span> {\n        return<\/span> \"\u6dfb\u52a0\u6210\u529f\"<\/span>;\n    }\n\n    @ApiImplicitParam(name = \"id\", value = \"\u7528\u6237ID\", required = true)<\/span>\n    @ApiOperation(\"DELETE\u8bf7\u6c42\uff0c\u5220\u9664\u65b9\u6cd5\")<\/span>\n    @DeleteMapping(\"\/del\")<\/span>\n    public<\/span> String del<\/span>(Long id)<\/span> {\n        return<\/span> \"\u5220\u9664\u6210\u529f\"<\/span>;\n    }\n}\n\n<\/code><\/pre>\n

AddReq.java<\/h4>\n
package<\/span> com.example.springbootswagger.req;\n\nimport<\/span> io.swagger.annotations.ApiModel;\nimport<\/span> io.swagger.annotations.ApiModelProperty;\n\n@ApiModel(\"\u6dfb\u52a0\u53c2\u6570\")<\/span>\npublic<\/span> class<\/span> AddReq<\/span> {\n\n    @ApiModelProperty(\"\u540d\u5b57\")<\/span>\n    private<\/span> String name;\n\n    @ApiModelProperty(\"\u5bc6\u7801\")<\/span>\n    private<\/span> String password;\n\n    public<\/span> String getName<\/span>()<\/span> {\n        return<\/span> name;\n    }\n\n    public<\/span> void<\/span> setName<\/span>(String name)<\/span> {\n        this<\/span>.name = name;\n    }\n\n    public<\/span> String getPassword<\/span>()<\/span> {\n        return<\/span> password;\n    }\n\n    public<\/span> void<\/span> setPassword<\/span>(String password)<\/span> {\n        this<\/span>.password = password;\n    }\n}\n\n<\/code><\/pre>\n

SpringbootSwaggerApplication.java<\/h4>\n
package<\/span> com.example.springbootswagger;\n\nimport<\/span> org.springframework.boot.SpringApplication;\nimport<\/span> org.springframework.boot.autoconfigure.SpringBootApplication;\nimport<\/span> springfox.documentation.swagger2.annotations.EnableSwagger2;\n\n@EnableSwagger2<\/span>\n@SpringBootApplication<\/span>\npublic<\/span> class<\/span> SpringbootSwaggerApplication<\/span> {\n\n    public<\/span> static<\/span> void<\/span> main<\/span>(String[] args)<\/span> {\n        SpringApplication.run(SpringbootSwaggerApplication.class, args);\n    }\n\n}\n\n<\/code><\/pre>\n

Word\u3001PDF\u7b49\u6587\u4ef6\u7c7b\u63a5\u53e3\u6587\u6863<\/h1>\n

\u4e3a\u4ec0\u4e48\u8fd8\u9700\u8981\u6587\u4ef6\u7c7b\u63a5\u53e3\u6587\u6863\u5462\uff1f\u9996\u5148\uff0cSwagger\u6587\u6863\u5b58\u5728\u517c\u5bb9\u6027\u95ee\u9898\uff0c\u6709\u4e9b\u7cfb\u7edf\u4e0d\u652f\u6301\uff0c\u8fd9\u65f6\u5019\u6587\u4ef6\u7c7b\u63a5\u53e3\u6587\u6863\u5c31\u80fd\u6d3e\u4e0a\u7528\u573a\u3002\u5176\u6b21\uff0cSwagger\u6587\u6863\u4e0d\u80fd\u79bb\u7ebf\u4f7f\u7528\uff0c\u5982\u679c\u7f51\u7edc\u4e0d\u7a33\u5b9a\u6216\u8005\u6ca1\u6709\u7f51\u7edc\u8fde\u63a5\uff0c\u5c31\u65e0\u6cd5\u67e5\u770b\u63a5\u53e3\u6587\u6863\uff0c\u800c\u6587\u4ef6\u7c7b\u63a5\u53e3\u6587\u6863\u53ef\u4ee5\u5728\u4efb\u4f55\u65f6\u5019\u79bb\u7ebf\u6d4f\u89c8\u3002<\/p>\n

\u4e4b\u524d\u6211\u6709\u5199\u8fc7\u4e00\u7bc7\u5173\u4e8e\u7cfb\u7edf\u95f4\u4ea4\u4e92\u7684\u6587\u7ae0:\u591a\u65b9\u5408\u4f5c\u65f6\uff0c\u7cfb\u7edf\u95f4\u7684\u4ea4\u4e92\u662f\u600e\u4e48\u505a\u7684\uff1f\uff0c\u7cfb\u7edf\u95f4\u7684\u63a5\u53e3\u4ea4\u4e92\u4e00\u822c\u63d0\u4f9b\u7684\u90fd\u662f\u6587\u4ef6\u7c7b\u6587\u6863\uff0c\u50cfWord\u3001PDF\u8fd9\u79cd\u3002<\/p>\n

\u5728\u5b9e\u9645\u5f00\u53d1\u4e2d\uff0c\u6211\u53d1\u73b0\u4e0d\u540c\u7684\u5f00\u53d1\u56e2\u961f\u63d0\u4f9b\u7684\u63a5\u53e3\u6587\u6863\u683c\u5f0f\u5b58\u5728\u5f88\u5927\u7684\u5dee\u5f02\u3002\u6709\u4e9b\u56e2\u961f\u63d0\u4f9b\u7684\u6587\u6863\u975e\u5e38\u8be6\u7ec6\uff0c\u751a\u81f3\u4f1a\u7ed9\u51fa\u8c03\u7528\u793a\u4f8b\u4ee3\u7801\uff0c\u800c\u6709\u4e9b\u56e2\u961f\u5219\u53ea\u63d0\u4f9b\u4e86\u975e\u5e38\u7b80\u5355\u7684\u63a5\u53e3\u8bf4\u660e\uff0c\u751a\u81f3\u8fde\u53c2\u6570\u8bf4\u660e\u90fd\u6ca1\u6709\u3002\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u63a5\u53e3\u6587\u6863\u5f88\u8be6\u7ec6\uff0c\u6211\u53ef\u4ee5\u5f88\u5feb\u5730\u8fdb\u884c\u8c03\u8bd5\u548c\u8054\u8c03\uff0c\u4f46\u662f\u5982\u679c\u6587\u6863\u4e0d\u591f\u8be6\u7ec6\uff0c\u5f88\u5bb9\u6613\u9047\u5230\u5404\u79cd\u5751\uff08\u4e00\u8a00\u96be\u5c3d\u7684\u5751\uff09\uff0c\u5fc5\u987b\u8981\u53bb\u627e\u5bf9\u65b9\u7684\u5f00\u53d1\u3002<\/p>\n

\u6211\u89c9\u5f97\u4e00\u4efd\u597d\u7684\u63a5\u53e3\u6587\u6863\u5e94\u8be5\u5305\u62ec\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/strong><\/p>\n

    \n
  • \n

    \u63a5\u53e3\u6982\u8ff0\uff1a\u5305\u62ec\u63a5\u53e3\u7684\u540d\u79f0\u3001\u63cf\u8ff0\u3001\u7248\u672c\u53f7\u7b49\u4fe1\u606f\uff0c\u8ba9\u5f00\u53d1\u8005\u4e86\u89e3\u63a5\u53e3\u7684\u57fa\u672c\u4fe1\u606f\u3002<\/p>\n<\/li>\n

  • \n

    \u63a5\u53e3\u53c2\u6570\uff1a\u5305\u62ec\u8bf7\u6c42\u53c2\u6570\u548c\u8fd4\u56de\u53c2\u6570\uff0c\u9700\u8981\u8be6\u7ec6\u8bf4\u660e\u6bcf\u4e2a\u53c2\u6570\u7684\u540d\u79f0\u3001\u7c7b\u578b\u3001\u63cf\u8ff0\u3001\u9ed8\u8ba4\u503c\u3001\u662f\u5426\u5fc5\u987b\u7b49\u4fe1\u606f\uff0c\u8ba9\u5f00\u53d1\u8005\u6e05\u6670\u5730\u77e5\u9053\u6bcf\u4e2a\u53c2\u6570\u7684\u542b\u4e49\u548c\u4f7f\u7528\u65b9\u6cd5\u3002<\/p>\n<\/li>\n

  • \n

    \u63a5\u53e3\u4f7f\u7528\u793a\u4f8b\uff1a\u63d0\u4f9b\u4e00\u4e2a\u6216\u591a\u4e2a\u8bf7\u6c42\u548c\u76f8\u5e94\u7684\u793a\u4f8b\uff0c\u8ba9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u7406\u89e3\u63a5\u53e3\u7684\u4f7f\u7528\u65b9\u6cd5\u548c\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n<\/li>\n

  • \n

    \u63a5\u53e3\u9519\u8bef\u7801\uff1a\u5217\u51fa\u6240\u6709\u53ef\u80fd\u51fa\u73b0\u7684\u9519\u8bef\u7801\u548c\u76f8\u5e94\u7684\u9519\u8bef\u4fe1\u606f\uff0c\u8ba9\u5f00\u53d1\u8005\u4e86\u89e3\u5982\u4f55\u8bc6\u522b\u548c\u5904\u7406\u63a5\u53e3\u8fd4\u56de\u7684\u9519\u8bef\u3002<\/p>\n<\/li>\n

  • \n

    \u63a5\u53e3\u9650\u5236\u548c\u5b89\u5168\u6027\uff1a\u5305\u62ec\u63a5\u53e3\u7684\u8bbf\u95ee\u9650\u5236\u3001\u9891\u6b21\u9650\u5236\u3001\u5b89\u5168\u6027\u7b49\u4fe1\u606f\uff0c\u8ba9\u5f00\u53d1\u8005\u77e5\u9053\u5982\u4f55\u6b63\u786e\u5730\u4f7f\u7528\u63a5\u53e3\u3002<\/p>\n<\/li>\n<\/ul>\n

    \u4ee5\u4e0b\u662f\u6211\u8ba4\u4e3a\u6837\u5f0f\u8f83\u4e3a\u7b80\u6d01\u548c\u6e05\u6670\u7684 Word \u6a21\u677f\u63a5\u53e3\u6587\u6863\u793a\u4f8b\uff08\u6700\u4e0b\u65b9\u662f\u6a21\u677f\u4e0b\u8f7d\u94fe\u63a5\uff09\uff1a \"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7<\/p>\n

    \u6a21\u677f\u4e0b\u8f7d\u94fe\u63a5<\/p>\n","protected":false},"excerpt":{"rendered":"\u7b80\u5355\u6613\u61c2\uff0c\u9ad8\u6548\u5b9e\u7528\u7684\u63a5\u53e3\u6587\u6863\u7f16\u5199\u6280\u5de7\u63a5\u53e3\u6587\u6863\u662f\u4e00\u4e2a\u8f6f\u4ef6\u7cfb\u7edf\u7684\u91cd\u8981\u7ec4\u6210\u90e8\u5206\uff0c\u5b83\u63cf\u8ff0\u4e86\u7cfb\u7edf\u4e2d\u6240\u6709\u53ef\u4f9b\u5916\u90e8\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u63a5...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[82],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/710"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}