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

简介: 采用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日志并进行多维度分析。
          目录
          相关文章
          |
          1天前
          |
          监控 Android开发 C语言
          深度解读Android崩溃日志案例分析2:tombstone日志
          深度解读Android崩溃日志案例分析2:tombstone日志
          100 0
          |
          1天前
          |
          存储 算法 数据挖掘
          带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(2)
          带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(2)
          111 1
          |
          1天前
          |
          监控 Java 数据库
          Spring事务相关配置、案例:转账业务追加日志及事务传播行为
          Spring事务相关配置、案例:转账业务追加日志及事务传播行为
          53 0
          |
          1天前
          |
          存储 安全 数据挖掘
          带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(1)
          带你读《Apache Doris 案例集》——06 Apache Doris 助力中国联通万亿日志数据分析提速10倍(1)
          |
          1天前
          |
          存储 监控 安全
          带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(1)
          带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(1)
          181 1
          |
          1天前
          |
          SQL 存储 安全
          带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(2)
          带你读《Apache Doris 案例集》——07查询平均提速700% ,奇安信基于 Apache Doris 升级日志安全分析系统(2)
          210 0
          |
          9月前
          |
          Java Spring
          案例08 AOP方式实现日志记录案例
          采用AOP的面向切面编程方式,对学生信息管理系统中的新增学生信息、更新学生信息和删除学生信息3个方法实现日志记录业务。
          59 0
          |
          6月前
          |
          编译器 Android开发
          深度解读Android崩溃日志案例分析1:so崩溃
          深度解读Android崩溃日志案例分析1:so崩溃
          117 1
          |
          6月前
          |
          监控 数据库
          136 日志监控告警系统案例(代码实现)
          136 日志监控告警系统案例(代码实现)
          83 0
          |
          6月前
          |
          监控
          135 日志监控告警系统案例(数据模型设计)
          135 日志监控告警系统案例(数据模型设计)
          84 0

          热门文章

          最新文章