案例07 OOP方式实现日志记录案例

本文涉及的产品
日志服务 SLS,月写入数据量 50GB 1个月
简介: 采用OOP的面向对象编程方式,对学生信息管理系统中的新增学生信息、更新学生信息和删除学生信息3个方法实现日志记录业务。

 采用OOP的面向对象编程方式,对学生信息管理系统中的新增学生信息、更新学生信息和删除学生信息3个方法实现日志记录业务。

1. 创建项目

Idea创建Java项目,项目名称为:case07-spring-oop。

2. 导入spring相关jar包

case07-spring-oop项目下创建lib目录,在lib目录下导入Jar包:

    • 核心包

    spring-core-5.3.25.jar

    spring-beans-5.3.25.jar

    spring-context-5.3.25.jar

    spring-expression-5.3.25.jar

      • AOP包

      spring-aop-5.3.25.jar

        • 测试包

        junit-4.6.jar

          • 依赖包

          commons-logging-1.2.jar

          3. 创建Spring配置文件

          src目录下创建applicationContext.xml配置文件。

          <beansxmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!-- 开启注解 --><context:component-scanbase-package="com.wfit.student"/></beans>


          4. 创建StudentDao类

          src目录下创建com.wfit.dao包,此包目录下创建StudentDao.java类。

          @RepositorypublicclassStudentDao {
          publicvoidaddStudent(){
          System.out.println("新增成功!");
              }
          publicvoiddelStudent(){
          System.out.println("删除成功!");
              }
          publicvoidgetStudent(){
          System.out.println("查询成功!");
              }
          }


          5. 创建StudentService接口

          src目录下创建com.wfit.service包,此包目录下创建StudentService.java接口。

          publicinterfaceStudentService {
          /*** 新增*/publicvoidaddStudent();
          /*** 删除*/publicvoiddelStudent();
          /*** 查询*/publicvoidgetStudent();
          }


          6. 创建StudentServiceImpl类

          src目录下创建com.wfit.service.impl包,此包目录下创建StudentServiceImpl.java类实现StudentService接口。

          publicinterfaceStudentService {
          /*** 新增*/publicvoidaddStudent();
          /*** 删除*/publicvoiddelStudent();
          /*** 查询*/publicvoidgetStudent();
          }


          7. 编写测试类

          src目录下创建com.wfit.test包,此包目录下创建TestStudent.java类。

          publicclassTestStudent {
          privateStudentServicestudentService;
          @Beforepublicvoidinit(){
          ApplicationContextapplicationContext=newClassPathXmlApplicationContext("applicationContext.xml");
          studentService=applicationContext.getBean("studentServiceImpl", StudentService.class);
              }
          @TestpublicvoidtestAdd(){
          studentService.addStudent();
              }
          @TestpublicvoidtestDel(){
          studentService.delStudent();
              }
          @TestpublicvoidtestGet(){
          studentService.getStudent();
              }
          }


          8. 执行结果



          相关实践学习
          日志服务之使用Nginx模式采集日志
          本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
          目录
          相关文章
          |
          4月前
          |
          存储 分布式计算 监控
          【Flume】Flume 监听日志文件案例分析
          【4月更文挑战第4天】【Flume】Flume 监听日志文件案例分析
          |
          4月前
          |
          存储 算法 数据挖掘
          带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(2)
          带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(2)
          214 1
          |
          4月前
          |
          监控 Android开发 C语言
          深度解读Android崩溃日志案例分析2:tombstone日志
          深度解读Android崩溃日志案例分析2:tombstone日志
          358 0
          |
          4月前
          |
          监控 Java 数据库
          Spring事务相关配置、案例:转账业务追加日志及事务传播行为
          Spring事务相关配置、案例:转账业务追加日志及事务传播行为
          69 0
          |
          4月前
          |
          存储 安全 数据挖掘
          带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(1)
          带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(1)
          199 1
          |
          16天前
          |
          Prometheus Cloud Native Go
          Golang语言之Prometheus的日志模块使用案例
          这篇文章是关于如何在Golang语言项目中使用Prometheus的日志模块的案例,包括源代码编写、编译和测试步骤。
          20 3
          Golang语言之Prometheus的日志模块使用案例
          |
          2月前
          |
          XML Java 数据格式
          支付系统----微信支付20---创建案例项目--集成Mybatis-plus的补充,target下只有接口的编译文件,xml文件了,添加日志的写法
          支付系统----微信支付20---创建案例项目--集成Mybatis-plus的补充,target下只有接口的编译文件,xml文件了,添加日志的写法
          |
          3月前
          |
          SQL 关系型数据库 MySQL
          MySQL数据库——索引(3)-索引语法(创建索引、查看索引、删除索引、案例演示),SQL性能分析(SQL执行频率,慢查询日志)
          MySQL数据库——索引(3)-索引语法(创建索引、查看索引、删除索引、案例演示),SQL性能分析(SQL执行频率,慢查询日志)
          45 2
          |
          4月前
          |
          存储 监控 安全
          带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(1)
          带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(1)
          216 1
          |
          3月前
          logrotate 日志文件管理工具介绍和经典案例
          logrotate 日志文件管理工具介绍和经典案例
          75 0