目录
-
使用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(); } }
- <dependency>
-