参考常见启动器
官网默认值
见官网 / pom父依赖
@SpringBootApplication:启动自动装配,配合 main + SpringApplication.run(.class,args)
@SpringBootTest:SpringBoot单元测试注解
@ConfigurationProperties:指定前缀读取配置文件对应属性,实现批量读取属性值
@Import:导入其他配置类 / 组件
@Conditional:条件化注入+@Bean 自己从来不用,第三方框架使用
@MapperScan:Mybatis提供的Spring扫描注解
创建IOC容器,初始化
解决办法,清除文件重新加载
WebMvcConfigurer 配置类 注册自定义拦截器配置拦截地址
依赖:原先mybatis依赖替换成场景启动器
config:yml配置 configuration typeAlias
mapper:MapperScan 扫描sql映射文件
接口文件:yml扫描接口
连接:spring配置连接池
调用:service配置mapper属性注入接口名,调用sql方法映射
导入依赖即可自动装配
声明式事务相关依赖为 jdbc二非tx
META-INF 目录:主要用于存放 Spring 配置文件、Maven 插件描述符、SPI 服务提供者列表以及其他元数据文件。
public, resources, META-INF/resources , static
参考
启动类以main方法作为项目入口 + @SpringBootApplication注解
SpringApplication.run 启动IOC容器
可以手动指定。不过@SpringBootApplication 中的@Component 是默认值,仅扫描所在包及其子包。不过其实按照约定放置Main方法位置就可以。
参考
ImportSelector是SpringBoot中功能性注解类似Enable…格式的核心接口,Enable注解会启动头上的Import,召唤一个神器就是ImportSelector实现类,并对相关配置类进行扫描装配。
类似的还有ImportBeanDefinitionRegister
YOUR_REPOSITROY\org\springframework\boot\spring-boot-autoconfigure\3.0.5\spring-boot-autoconfigure-3.0.5.jar!\META-INF\spring\org.springframework.boot.autoconfigure.AutoConfiguration.imports
如果你不想要导入的类被启动,可以在@SpringBootApplication中手动排除
概念:可变参数(varargs)是一种在方法声明中允许传递任意数量参数的机制。在 Java 中,可变参数通过在参数类型后面添加三个点 (…) 来表示。这种特性使得方法可以更加灵活地处理不同数量的输入参数
Demo:
import java.util.ArrayList;
import java.util.List;
public class VarargsExample {
// 打印多个数字
public static void printNumbers(int... numbers) {
System.out.print("Numbers: ");
for (int number : numbers) {
System.out.print(number + " ");
}
System.out.println();
}
// 创建并返回一个列表
public static List<String> createList(String... items) {
List<String> list = new ArrayList<>();
for (String item : items) {
list.add(item);
}
return list;
}
// 格式化字符串
public static String formatString(String template, Object... args) {
return String.format(template, args);
}
// 主方法
public static void main(String[] args) {
// 打印数字
printNumbers(1, 2, 3, 4, 5);
// 创建列表
List<String> fruits = createList("apple", "banana", "cherry");
System.out.println("Fruits: " + fruits);
// 格式化字符串
String greeting = formatString("Hello, %s! Today is %s.", "Alice", "Monday");
System.out.println(greeting);
}
}
为了让Mapper代理对象装配到IOC容器中,使得其他业务可以直接调用代理实例。
Spring Boot 会使用 MapperFactoryBean 来创建 MyBatis 的 Mapper 代理对象,并将其作为 Spring Bean 进行管理
暂存区没有版本概念,用来缓存未完成的版本工作
windows系统换行符问题,可以不用管
感觉是IDEA GIT插件的问题,如果你没有退出IDEA,可以右键项目找到更改历史取消。
如果你退出重进就没了。
所以还是确认没有问题就Commit吧
参考