Springboot如何使用面向切面编程AOP?

Springboot如何使用面向切面编程AOP?

在 Spring Boot 中使用面向切面编程(AOP)非常简单,Spring Boot 提供了对 AOP 的自动配置支持。以下是详细的步骤和示例,帮助你快速上手 Spring Boot 中的 AOP。


1. 添加依赖

首先,在 pom.xml(Maven)或 build.gradle.kts(Gradle)中添加 Spring Boot Starter AOP 依赖:

Maven
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId>
</dependency>
Gradle-Kotlin build.gradle.kts
dependencies {implementation("org.springframework.boot:spring-boot-starter-aop")
}
implementation("org.springframework.boot:spring-boot-starter-aop")
Gradle-Groovy build.gradle
dependencies {implementation 'org.springframework.boot:spring-boot-starter-aop'
}
implementation 'org.springframework.boot:spring-boot-starter-aop'

2. 编写切面类

切面类是一个普通的 Spring Bean,使用 @Aspect 注解标记。切面类中定义了切点(Pointcut)和通知(Advice)。

示例:记录方法执行日志的切面
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Aspect // 标记为切面类
@Component // 标记为 Spring Bean
public class LoggingAspect {// 定义切点:拦截 com.example.service 包下的所有方法@Pointcut("execution(* com.example.service.*.*(..))")public void serviceMethods() {}// 前置通知:在目标方法执行前执行@Before("serviceMethods()")public void logBeforeMethod() {System.out.println("方法即将执行...");}
}

3. 定义目标服务类

编写一个普通的 Spring 服务类,作为 AOP 的目标对象。

示例:用户服务类
import org.springframework.stereotype.Service;@Service
public class UserService {public void createUser(String name) {System.out.println("创建用户: " + name);}public void deleteUser(String name) {System.out.println("删除用户: " + name);}
}

4. 启用 AOP 支持

Spring Boot 默认会自动启用 AOP 支持,无需额外配置。如果需要手动启用,可以在主应用类上添加 @EnableAspectJAutoProxy 注解:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;@SpringBootApplication
@EnableAspectJAutoProxy // 启用 AOP 支持
public class MyApplication {public static void main(String[] args) {SpringApplication.run(MyApplication.class, args);}
}

5. 运行并验证

启动 Spring Boot 应用,调用 UserService 的方法,观察切面是否生效。

示例:调用服务方法
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;@Component
public class AppRunner implements CommandLineRunner {@Autowiredprivate UserService userService;@Overridepublic void run(String... args) throws Exception {userService.createUser("Alice");userService.deleteUser("Bob");}
}
输出结果
方法即将执行...
创建用户: Alice
方法即将执行...
删除用户: Bob

6. 常用 AOP 注解

Spring AOP 提供了多种通知类型,以下是常用的注解:

注解说明
@Before在目标方法执行前执行。
@After在目标方法执行后执行(无论是否抛出异常)。
@AfterReturning在目标方法成功返回后执行。
@AfterThrowing在目标方法抛出异常后执行。
@Around环绕通知,可以控制目标方法的执行(如修改参数、返回值或捕获异常)。
示例:环绕通知
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;@Aspect
@Component
public class TimingAspect {@Around("execution(* com.example.service.*.*(..))")public Object measureExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {long startTime = System.currentTimeMillis();Object result = joinPoint.proceed(); // 执行目标方法long endTime = System.currentTimeMillis();System.out.println("方法执行时间: " + (endTime - startTime) + "ms");return result;}
}

7. 切点表达式

切点表达式用于定义拦截的目标方法。以下是常见的表达式示例:

表达式说明
execution(* com.example.service.*.*(..))拦截 com.example.service 包下的所有方法。
execution(* com.example.service.UserService.*(..))拦截 UserService 类中的所有方法。
execution(* com.example.service.*.create*(..))拦截 com.example.service 包下以 create 开头的方法。
@annotation(com.example.LogExecutionTime)拦截带有 @LogExecutionTime 注解的方法。
自定义注解示例
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogExecutionTime {}

在方法上使用注解:

@Service
public class UserService {@LogExecutionTimepublic void createUser(String name) {System.out.println("创建用户: " + name);}
}

在切面中拦截注解:

@Aspect
@Component
public class LogExecutionTimeAspect {@Around("@annotation(com.example.LogExecutionTime)")public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {long startTime = System.currentTimeMillis();Object result = joinPoint.proceed();long endTime = System.currentTimeMillis();System.out.println("方法执行时间: " + (endTime - startTime) + "ms");return result;}
}

8. 总结

  • Spring Boot 通过 spring-boot-starter-aop 提供了对 AOP 的自动支持。
  • 使用 @Aspect 定义切面类,结合 @Before@After@Around 等注解实现通知。
  • 切点表达式(execution)用于定义拦截的目标方法。
  • 可以通过自定义注解实现更灵活的切面逻辑。

通过以上步骤,你可以在 Spring Boot 中轻松实现面向切面编程(AOP),增强代码的可维护性和可扩展性。








在Spring Boot中使用面向切面编程(AOP)通常涉及以下几个步骤:

1. 引入依赖

虽然Spring Boot的spring-boot-starter已经包含了AOP的依赖,但为了确保AOP功能被正确启用,你可以在pom.xml中显式添加spring-boot-starter-aop依赖(尽管这通常是可选的,因为spring-boot-starter-web等常用starter已经包含了它)。

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId>
</dependency>

2. 启用AOP

在Spring Boot中,你通常不需要显式启用AOP,因为@SpringBootApplication注解已经包含了@EnableAspectJAutoProxy,后者负责启用AOP代理。但是,如果你想要自定义AOP代理的行为(例如,使用CGLIB而不是JDK动态代理),你可以通过添加@EnableAspectJAutoProxy注解并设置其属性来实现。

@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true) // 使用CGLIB代理
public class MySpringBootApplication {public static void main(String[] args) {SpringApplication.run(MySpringBootApplication.class, args);}
}

然而,在大多数情况下,默认设置就足够了。

3. 定义切面类

切面类是一个用@Aspect注解标记的类,它包含了切点(pointcut)和通知(advice)。

  • 切点:定义了哪些方法将被拦截。
  • 通知:定义了拦截到方法时要执行的操作。
@Aspect
@Component
public class MyAspect {// 定义一个切点,匹配所有com.example.service包下的所有方法@Pointcut("execution(* com.example.service..*(..))")public void myPointcut() {// 这是一个空方法,仅用于定义切点表达式}// 在方法执行之前执行@Before("myPointcut()")public void beforeAdvice(JoinPoint joinPoint) {System.out.println("Before method: " + joinPoint.getSignature());}// 在方法执行之后执行(无论是否抛出异常)@After("myPointcut()")public void afterAdvice(JoinPoint joinPoint) {System.out.println("After method: " + joinPoint.getSignature());}// 在方法执行之后执行(仅当方法正常返回时)@AfterReturning(pointcut = "myPointcut()", returning = "result")public void afterReturningAdvice(JoinPoint joinPoint, Object result) {System.out.println("After returning method: " + joinPoint.getSignature() + " with result: " + result);}// 在方法抛出异常时执行@AfterThrowing(pointcut = "myPointcut()", throwing = "exception")public void afterThrowingAdvice(JoinPoint joinPoint, Throwable exception) {System.out.println("After throwing method: " + joinPoint.getSignature() + " with exception: " + exception);}// 环绕通知,可以在方法执行前后自定义逻辑@Around("myPointcut()")public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {System.out.println("Before proceeding method: " + joinPoint.getSignature());Object result = joinPoint.proceed(); // 执行目标方法System.out.println("After proceeding method: " + joinPoint.getSignature() + " with result: " + result);return result;}
}

4. 应用切面

一旦你定义了切面类并将其作为Spring组件(通过@Component注解)注册到Spring容器中,Spring AOP将自动应用这些切面到匹配的bean上。

注意事项

  • 切面类本身必须是一个Spring管理的bean,因此通常会在切面类上使用@Component或其他相关的Spring注解。
  • 切点表达式定义了哪些方法将被拦截。你可以使用AspectJ的切点表达式语言(Pointcut Expression Language, PEL)来编写复杂的切点表达式。
  • 通知方法可以有参数,这些参数可以是JoinPointProceedingJoinPoint(对于环绕通知)或任何由切点表达式捕获的参数(通过@Args注解)。
  • 环绕通知必须处理目标方法的调用(通过ProceedingJoinPoint.proceed()),并且可以返回结果或抛出异常。

通过以上步骤,你就可以在Spring Boot项目中成功使用AOP来实现横切关注点(如日志记录、事务管理、权限校验等)的分离。








在 Spring Boot 中使用面向切面编程(AOP)可以帮助你分离横切关注点,如日志记录、事务管理等,从主要业务逻辑中分离出来。Spring AOP 是基于代理的实现,默认情况下支持方法级别的拦截。下面是如何在 Spring Boot 应用中配置和使用 AOP 的步骤:

1. 添加依赖

首先,确保你的 build.gradlepom.xml 文件中包含了 spring-boot-starter-aop 依赖。

对于 Gradle,添加如下依赖到你的 build.gradle 文件:

dependencies {implementation 'org.springframework.boot:spring-boot-starter-aop'
}

对于 Maven,在你的 pom.xml 文件中添加:

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId>
</dependency>

2. 启用 AOP 支持

Spring Boot 自动配置了 AOP 支持,所以通常不需要额外的手动配置。但是,如果你的应用有多个配置类,确保它们被正确扫描到。一般情况下,只需保证主应用程序类或配置类上包含 @EnableAspectJAutoProxy 注解(尽管大多数情况下自动配置已经足够)。

import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;@Configuration
@EnableAspectJAutoProxy
public class AopConfig {
}

不过,如果你只是简单地使用 Spring Boot,并且没有特别复杂的配置需求,这个注解通常是不必要的,因为 Spring Boot 已经为你自动启用了 AOP 支持。

3. 创建一个切面

创建一个类并使用 @Aspect 注解标记它。然后,定义切入点(Pointcut)和通知(Advice),例如前置通知(@Before)、后置通知(@After)、返回通知(@AfterReturning)、异常通知(@AfterThrowing)和环绕通知(@Around)。

示例代码:

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;@Aspect
@Component
public class LoggingAspect {@Before("execution(* com.example.demo.service.*.*(..))")public void beforeMethodExecution() {System.out.println("A method in the service layer is about to be called.");}
}

4. 定义切入点表达式

上述例子中的 "execution(* com.example.demo.service.*.*(..))" 是一个切入点表达式,表示匹配 com.example.demo.service 包下的所有类的所有方法。你可以根据需要调整此表达式来精确控制哪些方法会被拦截。

5. 测试你的切面

最后,编写一些测试用例或者运行你的应用来验证 AOP 切面是否按预期工作。确保目标方法被调用时,相应的通知也会被执行。

通过以上步骤,你应该能够在 Spring Boot 应用中成功配置并使用 AOP。这种方式不仅能够帮助你清晰地分离关注点,还能使代码更加简洁和易于维护。








在 Spring Boot 中使用面向切面编程(AOP)可以高效地实现日志记录、事务管理、权限校验等横切关注点。以下是 详细步骤和实际应用场景 的总结:


1. 添加依赖

Spring Boot 默认通过 spring-boot-starter-aop 提供对 AOP 的自动配置支持:

Maven
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId>
</dependency>
Gradle
dependencies {implementation("org.springframework.boot:spring-boot-starter-aop")
}

2. 编写切面类

切面类需用 @Aspect@Component 注解标记,定义切点和通知。

示例:日志记录切面
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;@Aspect
@Component
public class LoggingAspect {// 定义切点:拦截 service 包下的所有方法@Pointcut("execution(* com.example.service.*.*(..))")public void serviceMethods() {}// 前置通知:方法执行前记录日志@Before("serviceMethods()")public void logMethodStart() {System.out.println("方法开始执行...");}// 后置通知:方法执行后记录日志(无论是否异常)@After("serviceMethods()")public void logMethodEnd() {System.out.println("方法执行结束。");}// 环绕通知:计算方法执行时间@Around("serviceMethods()")public Object measureTime(ProceedingJoinPoint joinPoint) throws Throwable {long start = System.currentTimeMillis();Object result = joinPoint.proceed(); // 执行目标方法long end = System.currentTimeMillis();System.out.println("方法执行耗时: " + (end - start) + "ms");return result;}
}

3. 定义目标服务

编写一个普通的 Spring Bean 作为切面拦截的目标。

示例:用户服务
@Service
public class UserService {public void createUser(String name) {System.out.println("创建用户: " + name);}
}

4. 验证效果

调用 UserService 的方法时,切面逻辑自动生效:

@SpringBootApplication
public class Application {public static void main(String[] args) {ConfigurableApplicationContext context = SpringApplication.run(Application.class, args);UserService userService = context.getBean(UserService.class);userService.createUser("Alice");}
}
输出结果
方法开始执行...
创建用户: Alice
方法执行结束。
方法执行耗时: 2ms

5. 核心注解详解

(1) 切点表达式(Pointcut)
  • 语法execution(修饰符 返回类型 包名.类名.方法名(参数类型))
  • 常用示例
    • execution(* com.example.service.*.*(..)):拦截 service 包下所有类的所有方法。
    • execution(* com.example.service.UserService.create*(..)):拦截 UserService 中以 create 开头的方法。
    • @annotation(com.example.LogTrack):拦截带有 @LogTrack 注解的方法。
(2) 通知类型(Advice)
注解说明
@Before目标方法执行前触发。
@After目标方法执行后触发(无论是否抛出异常)。
@AfterReturning目标方法成功返回后触发(可获取返回值)。
@AfterThrowing目标方法抛出异常后触发(可捕获异常对象)。
@Around包裹目标方法,可控制方法执行、修改参数或返回值。
示例:获取方法参数和返回值
@Aspect
@Component
public class DataAspect {@AfterReturning(pointcut = "execution(* com.example.service.*.*(..))",returning = "result")public void logResult(Object result) {System.out.println("方法返回值: " + result);}@Before("execution(* com.example.service.*.*(..)) && args(name)")public void logArgument(String name) {System.out.println("方法参数: " + name);}
}

6. 高级用法

(1) 自定义注解实现切面

定义注解标记需要拦截的方法,提高代码可读性。

步骤1:定义注解
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface LogTrack {}
步骤2:在方法上使用注解
@Service
public class OrderService {@LogTrackpublic void placeOrder(String orderId) {System.out.println("下单成功: " + orderId);}
}
步骤3:切面拦截注解
@Aspect
@Component
public class LogTrackAspect {@Around("@annotation(com.example.LogTrack)")public Object trackMethod(ProceedingJoinPoint joinPoint) throws Throwable {System.out.println("开始追踪方法...");Object result = joinPoint.proceed();System.out.println("追踪结束。");return result;}
}

(2) 处理异常

@AfterThrowing 中捕获并处理异常。

@Aspect
@Component
public class ExceptionAspect {@AfterThrowing(pointcut = "execution(* com.example.service.*.*(..))",throwing = "ex")public void handleException(Exception ex) {System.out.println("捕获异常: " + ex.getMessage());// 发送报警邮件或记录日志}
}

7. 常见问题与解决

问题1:切面未生效
  • 原因
    • 切面类未被 Spring 管理(缺少 @Component)。
    • 切点表达式未匹配到目标方法。
    • 目标方法未被 Spring 代理(如直接通过 new 创建对象)。
  • 解决
    • 确保切面类添加了 @Component
    • 使用 @Autowired 获取 Bean,而非直接实例化。
问题2:环绕通知未调用 proceed()
  • 现象:目标方法未执行。
  • 解决:在 @Around 方法中必须调用 joinPoint.proceed()

8. 实际应用场景

  1. 日志记录:自动记录方法入参、返回值、执行时间。
  2. 事务管理:结合 @Transactional 实现声明式事务。
  3. 权限校验:在方法执行前检查用户权限。
  4. 性能监控:统计接口耗时,优化慢查询。
  5. 缓存管理:在方法执行前后操作缓存(如 Redis)。

总结

Spring Boot 通过简化配置和自动代理机制,使得 AOP 的实现非常便捷。核心步骤:

  1. 添加 spring-boot-starter-aop 依赖。
  2. 使用 @Aspect@Component 定义切面类。
  3. 通过切点表达式精准定位目标方法。
  4. 选择合适的通知类型(@Before@Around 等)实现横切逻辑。

掌握 AOP 后,可以大幅减少重复代码,提升系统的可维护性和扩展性。








本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/69134.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

专业学习|一文了解并实操自适应大邻域搜索(讲解代码)

一、自适应大邻域搜索概念介绍 自适应大邻域搜索&#xff08;Adaptive Large Neighborhood Search&#xff0c;ALNS&#xff09;是一种用于解决组合优化问题的元启发式算法。以下是关于它的详细介绍&#xff1a; -自适应大领域搜索的核心思想是&#xff1a;破坏解、修复解、动…

TensorFlow深度学习实战(6)——回归分析详解

TensorFlow深度学习实战&#xff08;6&#xff09;——回归分析详解 0. 前言1. 回归分析简介2. 线性回归2.1 简单线性回归2.2 多重线性回归2.3 多元线性回归 3. 构建基于线性回归的神经网络3.1 使用 TensorFlow 进行简单线性回归3.2 使用 TensorFlow 进行多元线性回归和多重线性…

2024年12月 Scratch 图形化(二级)真题解析 中国电子学会全国青少年软件编程等级考试

202412 Scratch 图形化&#xff08;二级&#xff09;真题解析 中国电子学会全国青少年软件编程等级考试 一、单选题(共25题&#xff0c;共50分) 第 1 题 小猫初始位置和方向如下图所示&#xff0c;下面哪个选项能让小猫吃到老鼠&#xff1f;&#xff08; &#xff09; A. B. …

Java 面试合集(2024版)

种自己的花&#xff0c;爱自己的宇宙 目录 第一章-Java基础篇 1、你是怎样理解OOP面向对象??? 难度系数&#xff1a;? 2、重载与重写区别??? 难度系数&#xff1a;? 3、接口与抽象类的区别??? 难度系数&#xff1a;? 4、深拷贝与浅拷贝的理解??? 难度系数&…

Math Reference Notes: 符号函数

1. 符号函数的定义 符号函数&#xff08;Sign Function&#xff09; sgn ( x ) \text{sgn}(x) sgn(x) 是一个将实数 ( x ) 映射为其 符号值&#xff08;即正数、负数或零&#xff09;的函数。 它的定义如下&#xff1a; sgn ( x ) { 1 如果 x > 0 0 如果 x 0 − 1 如…

一文了解边缘计算

什么是边缘计算&#xff1f; 我们可以通过一个最简单的例子来理解它&#xff0c;它就像一个司令员&#xff0c;身在离炮火最近的前线&#xff0c;汇集现场所有的实时信息&#xff0c;经过分析并做出决策&#xff0c;及时果断而不拖延。 1.什么是边缘计算&#xff1f; 边缘计算…

108,【8】 buuctf web [网鼎杯 2020 青龙组]AreUSerialz

进入靶场 <?php // 包含 flag.php 文件&#xff0c;通常这个文件可能包含敏感信息&#xff0c;如 flag include("flag.php");// 高亮显示当前文件的源代码&#xff0c;方便查看代码结构和逻辑 highlight_file(__FILE__);// 定义一个名为 FileHandler 的类&#x…

《redis哨兵机制》

【redis哨兵机制导读】上一节介绍了redis主从同步的机制&#xff0c;但大家有没有想过一种场景&#xff0c;比如&#xff1a;主库突然挂了&#xff0c;那么按照读写分离的设计思想&#xff0c;此时redis集群只有从库才能提供读服务&#xff0c;那么写服务该如何提供&#xff0c…

【赵渝强老师】Spark RDD的依赖关系和任务阶段

Spark RDD彼此之间会存在一定的依赖关系。依赖关系有两种不同的类型&#xff1a;窄依赖和宽依赖。 窄依赖&#xff1a;如果父RDD的每一个分区最多只被一个子RDD的分区使用&#xff0c;这样的依赖关系就是窄依赖&#xff1b;宽依赖&#xff1a;如果父RDD的每一个分区被多个子RD…

开源数据分析工具 RapidMiner

RapidMiner是一款功能强大且广泛应用的数据分析工具&#xff0c;其核心功能和特点使其成为数据科学家、商业分析师和预测建模人员的首选工具。以下是对RapidMiner的深度介绍&#xff1a; 1. 概述 RapidMiner是一款开源且全面的端到端数据科学平台&#xff0c;支持从数据准备、…

蓝桥杯备考:二维前缀和算法模板题(二维前缀和详解)

【模板】二维前缀和 这道题如果我们暴力求解的话&#xff0c;时间复杂度就是q次查询里套两层循环最差的时候要遍历整个矩阵也就是O&#xff08;q*n*m) 由题目就是10的11次方&#xff0c;超时 二维前缀和求和的公式&#xff08;创建需要用到&#xff09;f[i][j]就是从&#xf…

3-track_hacker/2018网鼎杯

3-track_hacker 打开附件 使用Wireshark打开。过滤器过滤http,看里面有没有flag.txt 发现有 得到&#xff1a;eJxLy0lMrw6NTzPMS4n3TVWsBQAz4wXi base64解密 import base64 import zlibc eJxLy0lMrw6NTzPMS4n3TVWsBQAz4wXi decoded base64.b64decode(c) result zlib.deco…

第二十章 存储函数

目录 一、概述 二、语法 三、示例 一、概述 前面章节中&#xff0c;我们详细讲解了MySQL中的存储过程&#xff0c;掌握了存储过程之后&#xff0c;学习存储函数则肥仓简单&#xff0c;存储函数其实是一种特殊的存储过程&#xff0c;也就是有返回值的存储过程。存储函数的参数…

Linux:文件系统(软硬链接)

目录 inode ext2文件系统 Block Group 超级块&#xff08;Super Block&#xff09; GDT&#xff08;Group Descriptor Table&#xff09; 块位图&#xff08;Block Bitmap&#xff09; inode位图&#xff08;Inode Bitmap&#xff09; i节点表&#xff08;inode Tabl…

java求职学习day27

数据库连接池 &DBUtils 1.数据库连接池 1.1 连接池介绍 1) 什么是连接池 实际开发中 “ 获得连接 ” 或 “ 释放资源 ” 是非常消耗系统资源的两个过程&#xff0c;为了解决此类性能问题&#xff0c;通常情况我们 采用连接池技术&#xff0c;来共享连接 Connection 。…

机器学习--2.多元线性回归

多元线性回归 1、基本概念 1.1、连续值 1.2、离散值 1.3、简单线性回归 1.4、最优解 1.5、多元线性回归 2、正规方程 2.1、最小二乘法 2.2、多元一次方程举例 2.3、矩阵转置公式与求导公式 2.4、推导正规方程0的解 2.5、凸函数判定 成年人最大的自律就是&#xff1a…

Docker 部署 ClickHouse 教程

Docker 部署 ClickHouse 教程 背景 ClickHouse 是一个开源的列式数据库管理系统&#xff08;DBMS&#xff09;&#xff0c;主要用于在线分析处理&#xff08;OLAP&#xff09;。它专为大数据的实时分析设计&#xff0c;支持高速的查询性能和高吞吐量。ClickHouse 以其高效的数…

建表注意事项(2):表约束,主键自增,序列[oracle]

没有明确写明数据库时,默认基于oracle 约束的分类 用于确保数据的完整性和一致性。约束可以分为 表级约束 和 列级约束&#xff0c;区别在于定义的位置和作用范围 复合主键约束: 主键约束中有2个或以上的字段 复合主键的列顺序会影响索引的使用&#xff0c;需谨慎设计 添加…

Google C++ Style / 谷歌C++开源风格

文章目录 前言1. 头文件1.1 自给自足的头文件1.2 #define 防护符1.3 导入你的依赖1.4 前向声明1.5 内联函数1.6 #include 的路径及顺序 2. 作用域2.1 命名空间2.2 内部链接2.3 非成员函数、静态成员函数和全局函数2.4 局部变量2.5 静态和全局变量2.6 thread_local 变量 3. 类3.…

【HTML入门】Sublime Text 4与 Phpstorm

文章目录 前言一、环境基础1.Sublime Text 42.Phpstorm(1)安装(2)启动Phpstorm(3)“启动”码 二、HTML1.HTML简介(1)什么是HTML(2)HTML版本及历史(3)HTML基本结构 2.HTML简单语法(1)HTML标签语法(2)HTML常用标签(3)表格(4)特殊字符 总结 前言 在当今的软件开发领域&#xff0c…