做网站开发注册工商户可以么,域名网安备案,广东网站建设哪家,做网站素材图片接上一项目【springboot】简易模块化开发项目整合MyBatis-plus#xff0c;进行拓展项目
1.新建模块
右键项目→New→Module#xff0c;新建一个模块 父项目选择fast-demo#xff0c;命名为fast-demo-config#xff0c;用于存放所有配置项 添加后#xff0c;项目结构如图…接上一项目【springboot】简易模块化开发项目整合MyBatis-plus进行拓展项目
1.新建模块
右键项目→New→Module新建一个模块 父项目选择fast-demo命名为fast-demo-config用于存放所有配置项 添加后项目结构如图 2.添加swagger依赖
fast-demo-config模块的pom.xml中添加swagger依赖 dependenciesdependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger-ui/artifactIdversion2.8.0/version/dependencydependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger2/artifactIdversion2.8.0/version/dependencydependencygroupIdjavax.xml.bind/groupIdartifactIdjaxb-api/artifactIdversion2.3.0/version/dependency/dependencies在fast-demo-config模块新建SwaggerConfig类用于配置swagger相关设置配置内容如下
Configuration
EnableSwagger2
ConditionalOnProperty(name swagger.enable, havingValue true)
public class SwaggerConfig {public Docket createRestApi(){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()// 这里填写的是controller层的路径填写自己的.apis(RequestHandlerSelectors.basePackage(com.cyfy.fastdemo.controller)).paths(PathSelectors.any()).build();}private ApiInfo apiInfo(){return new ApiInfoBuilder().title(页面标题).contact(new Contact(创建人名称,项目路径,邮箱)).version(版本号).description(描述).build();}
}项目结构如图 3.swagger测试
fast-demo-web模块中导入fast-demo-config模块 dependencygroupIdcom.cyfy/groupIdartifactIdfast-demo-config/artifactIdversion0.0.1-SNAPSHOT/version/dependency进入application.yml配置文件中增加如下字段
swagger:enable: true进入fast-demo-web模块中d UserController类中增加swagger注解内容
RestController
Api(用户信息接口)
public class UserController {Autowiredprivate UserService userService;RequestMapping(/user)ApiOperation(value 获取所有用户信息, notes 返回用户信息)public ListUser getUserList(){return userService.getUserList();}
}运行项目后浏览器输入http://localhost:8080/swagger-ui.html便可查看到相关接口文档 项目结构 fast-demo-config模块 pom.xml ?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdfast-demo/artifactIdgroupIdcom.cyfy/groupIdversion0.0.1-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdfast-demo-config/artifactIdpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependenciesdependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger-ui/artifactId/dependencydependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger2/artifactId/dependencydependencygroupIdjavax.xml.bind/groupIdartifactIdjaxb-api/artifactId/dependency/dependencies
/projectSwaggerConfig package com.cyfy.fastdemo.config;import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;Configuration
EnableSwagger2
ConditionalOnProperty(name swagger.enable, havingValue true)
public class SwaggerConfig {public Docket createRestApi(){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.basePackage(com.cyfy.fastdemo.controller)).paths(PathSelectors.any()).build();}private ApiInfo apiInfo(){return new ApiInfoBuilder().title(页面标题).contact(new Contact(创建人名称,项目路径,邮箱)).version(版本号).description(描述).build();}
}fast-demo-web模块 pom.xml ?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentartifactIdfast-demo/artifactIdgroupIdcom.cyfy/groupIdversion0.0.1-SNAPSHOT/version/parentmodelVersion4.0.0/modelVersionartifactIdfast-demo-web/artifactIdpackagingpom/packagingmodulesmodulefast-demo-controller/modulemodulefast-demo-service/modulemodulefast-demo-dao/module/modulespropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target/propertiesdependencies!--引入mybatisPlus 包含了 jdbc--dependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactId/dependency!--mysql--dependencygroupIdmysql/groupIdartifactIdmysql-connector-java/artifactId/dependency!-- 导入工具配置模块 --dependencygroupIdcom.cyfy/groupIdartifactIdfast-demo-config/artifactIdversion0.0.1-SNAPSHOT/version/dependency/dependencies
/projectfast-demo-controller模块 application.yml # 数据库连接配置,记得新建一个数据库
spring:datasource:url: jdbc:mysql://localhost:3306/my_demo?useUnicodetruecharacterEncodingUTF-8driver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: 123456mvc:pathmatch:matching-strategy: ant_path_matchermybatis-plus:# 指定 Mapper XML 文件的位置使用 classpath 通配符指定路径mapper-locations: classpath:/mapper/**/*.xml# 指定实体类的包路径用于自动扫描并注册类型别名type-aliases-package: com.cyfy.springboot_one.pojoglobal-config:db-config:id-type: input# 驼峰下划线转换将数据库字段的下划线命名规则转换为 Java 实体类属性的驼峰命名规则db-column-underline: true# 刷新 mapperrefresh-mapper: trueconfiguration:# 将 Java 实体类属性的驼峰命名规则转换为数据库字段的下划线命名规则map-underscore-to-camel-case: true# 查询结果中包含空值的列在映射的时候不会映射这个字段call-setters-on-nulls: true# 开启 sql 日志log-impl: org.apache.ibatis.logging.stdout.StdOutImpl# 关闭 sql 日志# log-impl: org.apache.ibatis.logging.nologging.NoLoggingImplswagger:enable: trueUserController package com.cyfy.fastdemo.controller;import com.cyfy.fastdemo.entity.User;
import com.cyfy.fastdemo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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 java.util.List;RestController
Api(用户信息接口)
public class UserController {Autowiredprivate UserService userService;RequestMapping(value /user,method RequestMethod.GET)ApiOperation(value 获取所有用户信息, notes 返回用户信息)public ListUser getUserList(){return userService.getUserList();}
}
fast-demo模块 pom.xml ?xml version1.0 encodingUTF-8?
project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.cyfy/groupIdartifactIdfast-demo/artifactIdpackagingpom/packagingversion0.0.1-SNAPSHOT/versionmodulesmodulefast-demo-web/modulemodulefast-demo-config/module/modulesnamefast-demo/namedescriptionDemo project for Spring Boot/descriptionpropertiesjava.version1.8/java.versionproject.build.sourceEncodingUTF-8/project.build.sourceEncodingproject.reporting.outputEncodingUTF-8/project.reporting.outputEncodingspring-boot.version2.6.13/spring-boot.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency/dependenciesdependencyManagementdependenciesdependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger-ui/artifactIdversion2.8.0/version/dependencydependencygroupIdio.springfox/groupIdartifactIdspringfox-swagger2/artifactIdversion2.8.0/version/dependencydependencygroupIdjavax.xml.bind/groupIdartifactIdjaxb-api/artifactIdversion2.3.0/version/dependencydependencygroupIdcom.baomidou/groupIdartifactIdmybatis-plus-boot-starter/artifactIdversion3.5.2/version/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-dependencies/artifactIdversion${spring-boot.version}/versiontypepom/typescopeimport/scope/dependency/dependencies/dependencyManagementbuildpluginsplugingroupIdorg.apache.maven.plugins/groupIdartifactIdmaven-compiler-plugin/artifactIdversion3.8.1/versionconfigurationsource1.8/sourcetarget1.8/targetencodingUTF-8/encoding/configuration/pluginplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdversion${spring-boot.version}/versionconfigurationmainClasscom.cyfy.fastdemo.FastDemoApplication/mainClassskiptrue/skip/configurationexecutionsexecutionidrepackage/idgoalsgoalrepackage/goal/goals/execution/executions/plugin/plugins/build/project