云尚办公系统:搭建环境

目录

使用dependencyManagemen

依赖传递

MyBatis-Plus入门

knife4j



  • 使用dependencyManagemen

                <!--配置dependencyManagement锁定依赖的版本-->
                            <dependencyManagement>
                                        <dependencies>

                如果第一次导入,可以那应该将<dependencyManagement>标签注释掉,用来导入依赖,否则会一直报错

  • 依赖传递

    •  <dependencies>
              <dependency>
                  <groupId>com.atguigu</groupId>
                  <artifactId>common-util</artifactId>
                  <version>1.0-SNAPSHOT</version>
              </dependency>

      •        在这里使用了maven的依赖传递,直接使用父模块的依赖

<dependencyManagement>的作用是统一管理版本信息
在子工程中使用时,还是需要引入坐标的,但是不需要给出version

pom文件中,当子项目中引用一个依赖而不用显示的列出版本号,
Maven会沿着父子层次向上找,直到找到一个拥有<dependencyManagement>元素的项目,然后它就会使用在这个<dependencyManagement>元素中指定的版本号;若找不到则报错。

2.2、依赖原则
依赖原则目的:防止jar包的冲突
为了避免造成依赖重复,需要选择一个依赖路径

2.2.1、路径最短优先原则
即优先选择传递路径最短的依赖包

2.2.2、路径长度相同
路径长度相同的情况下,又可以分为是否有在同一个pom.xml两种情况

覆盖
如果在同一pom.xml文件中有2个相同的依赖;后面声明的会覆盖前面的依赖
但这里要说严禁使用本情况,严禁在同一个pom中声明两个不同的依赖
优先
如果是在不同pom.xml中有2个相同的依赖;则先声明的依赖,会覆盖后面声明的依赖

  • MyBatis-Plus入门

    • @TableName:表名注解,标识实体类对应的表

      @TableId:主键注解,type = IdType.AUTO(数据库 ID 自增)

      @TableField:字段注解(非主键)

      @TableLogic:逻辑删除 MyBatis-Plus条件构造器

  • MyBatis-Plus条件构造器

    • @Test
      public void testSelect1() {
          QueryWrapper<SysRole> queryWrapper = new QueryWrapper<>();
          queryWrapper.eq("role_code", "role");
          List<SysRole> users = sysRoleMapper.selectList(queryWrapper);
          System.out.println(users);
      }

      @Test
      public void testSelect2() {
          LambdaQueryWrapper<SysRole> queryWrapper = new LambdaQueryWrapper<>();
          queryWrapper.eq(SysRole::getRoleCode, "role");
          List<SysRole> users = sysRoleMapper.selectList(queryWrapper);
          System.out.println(users);
      }

    • knife4j

      • <dependency>
            <groupId>com.github.xiaoymin</groupId>
            <artifactId>knife4j-spring-boot-starter</artifactId>
        </dependency>
      • 配置类
      • package com.atguigu.common.config.knife4j;
        
        import org.springframework.context.annotation.Bean;
        import org.springframework.context.annotation.Configuration;
        import springfox.documentation.builders.ApiInfoBuilder;
        import springfox.documentation.builders.ParameterBuilder;
        import springfox.documentation.builders.PathSelectors;
        import springfox.documentation.builders.RequestHandlerSelectors;
        import springfox.documentation.schema.ModelRef;
        import springfox.documentation.service.ApiInfo;
        import springfox.documentation.service.Contact;
        import springfox.documentation.service.Parameter;
        import springfox.documentation.spi.DocumentationType;
        import springfox.documentation.spring.web.plugins.Docket;
        import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;
        
        import java.util.ArrayList;
        import java.util.List;
        
        /**
         * knife4j配置信息
         */
        @Configuration
        @EnableSwagger2WebMvc
        public class Knife4jConfig {
        
            @Bean
            public Docket adminApiConfig(){
                List<Parameter> pars = new ArrayList<>();
                ParameterBuilder tokenPar = new ParameterBuilder();
                tokenPar.name("token")
                        .description("用户token")
                        .defaultValue("")
                        .modelRef(new ModelRef("string"))
                        .parameterType("header")
                        .required(false)
                        .build();
                pars.add(tokenPar.build());
                //添加head参数end
        
                Docket adminApi = new Docket(DocumentationType.SWAGGER_2)
                        .groupName("adminApi")
                        .apiInfo(adminApiInfo())
                        .select()
                        //只显示admin路径下的页面
                        .apis(RequestHandlerSelectors.basePackage("com.atguigu"))
                        .paths(PathSelectors.regex("/admin/.*"))
                        .build()
                        .globalOperationParameters(pars);
                return adminApi;
            }
        
            private ApiInfo adminApiInfo(){
        
                return new ApiInfoBuilder()
                        .title("后台管理系统-API文档")
                        .description("本文档描述了后台管理系统微服务接口定义")
                        .version("1.0")
                        .contact(new Contact("atguigu", "http://atguigu.com", "atguigu@qq.com"))
                        .build();
            }
        
        
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值