原始的xml文件

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE tris SYSTEM "../dtd/tris.dtd">
<tris number="12">
0.046776 -0.922290 0.129226 
0.043791 -0.913621 0.168911 
-0.046622 -0.923499 0.129251 
-0.046622 -0.923499 0.129251 
-0.041116 0.915566 0.130949 
0.046776 -0.922290 0.129226 
0.046776 -0.922290 0.129226 
-0.041116 0.915566 0.130949 
0.040947 0.921809 0.130948 
-0.041118 0.908294 0.163068 
-0.041116 0.915566 0.130949 
-0.046622 -0.923499 0.129251 
0.040947 0.921809 0.130948 
-0.041116 0.915566 0.130949 
-0.041118 0.908294 0.163068 
0.043791 -0.913621 0.168911 
-0.043535 -0.913465 0.168910 
-0.046622 -0.923499 0.129251 
-0.041118 0.908294 0.163068 
-0.046622 -0.923499 0.129251 
-0.043535 -0.913465 0.168910 
-0.041118 0.908294 0.163068 
0.041361 0.908159 0.163068 
0.040947 0.921809 0.130948 
0.040947 0.921809 0.130948 
0.041361 0.908159 0.163068 
0.046776 -0.922290 0.129226 
0.046776 -0.922290 0.129226 
0.041361 0.908159 0.163068 
0.043791 -0.913621 0.168911 
0.043791 -0.913621 0.168911 
0.041361 0.908159 0.163068 
-0.043535 -0.913465 0.168910 
-0.043535 -0.913465 0.168910 
0.041361 0.908159 0.163068 
-0.041118 0.908294 0.163068 
</tris>
<!-- End Of File: CRCUpdate -->

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 创建项目 首先,我们需要创建一个基于Maven的Spring项目。在pom.xml文件中添加以下依赖项: ```xml <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.2.8.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.2.8.RELEASE</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>5.2.8.RELEASE</version> </dependency> </dependencies> ``` 2. 创建目录结构 在src/main目录下创建以下目录结构: ``` src/main/java └── com └── example └── aop ├── aspect │ ├── AfterReturningAspect.java │ ├── AfterThrowingAspect.java │ ├── AroundAspect.java │ ├── BeforeAspect.java │ └── LoggingAspect.java ├── service │ ├── CustomerService.java │ └── CustomerServiceImpl.java └── MainApp.java ``` 3. 编写Java类 3.1 CustomerService接口 ```java public interface CustomerService { void addCustomer(); String addCustomerReturnValue(); void addCustomerThrowException() throws Exception; void addCustomerAround(String name); } ``` 3.2 CustomerServiceImpl实现类 ```java public class CustomerServiceImpl implements CustomerService { private String name; private String url; public void setName(String name) { this.name = name; } public void setUrl(String url) { this.url = url; } public void addCustomer() { System.out.println("addCustomer() is running "); } public String addCustomerReturnValue() { System.out.println("addCustomerReturnValue() is running "); return "abc"; } public void addCustomerThrowException() throws Exception { System.out.println("addCustomerThrowException() is running "); throw new Exception("Generic Error"); } public void addCustomerAround(String name){ System.out.println("addCustomerAround() is running, args : " + name); } } ``` 3.3 日志切面类 ```java public class LoggingAspect { public void beforeAdvice(JoinPoint joinPoint){ System.out.println("Going to setup student profile."); } public void afterAdvice(JoinPoint joinPoint){ System.out.println("Student profile has been setup."); } public void afterReturningAdvice(Object retVal){ System.out.println("Returning:" + retVal.toString() ); } public void AfterThrowingAdvice(IllegalArgumentException ex){ System.out.println("There has been an exception: " + ex.toString()); } public void aroundAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { System.out.println("Around advice : Before method execution"); proceedingJoinPoint.proceed(); System.out.println("Around advice : After method execution"); } } ``` 3.4 AspectJ切面类 ```java public class BeforeAspect { public void beforeAdvice(JoinPoint joinPoint){ System.out.println("Before method:" + joinPoint.getSignature()); } } ``` ```java public class AfterReturningAspect { public void afterReturningAdvice(Object retVal){ System.out.println("Returning:" + retVal.toString() ); } } ``` ```java public class AfterThrowingAspect { public void AfterThrowingAdvice(IllegalArgumentException ex){ System.out.println("There has been an exception: " + ex.toString()); } } ``` ```java public class AroundAspect { public void aroundAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { System.out.println("Around advice : Before method execution"); proceedingJoinPoint.proceed(); System.out.println("Around advice : After method execution"); } } ``` 4. 编写配置文件 4.1 applicationContext.xml ```xml <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"> <!-- bean definition --> <bean id="customerService" class="com.example.aop.service.CustomerServiceImpl"> <property name="name" value="Cnblogs" /> <property name="url" value="http://www.cnblogs.com" /> </bean> <!-- AspectJ Config --> <bean id="loggingAspect" class="com.example.aop.aspect.LoggingAspect"></bean> <bean id="beforeAspect" class="com.example.aop.aspect.BeforeAspect"></bean> <bean id="afterReturningAspect" class="com.example.aop.aspect.AfterReturningAspect"></bean> <bean id="afterThrowingAspect" class="com.example.aop.aspect.AfterThrowingAspect"></bean> <bean id="aroundAspect" class="com.example.aop.aspect.AroundAspect"></bean> <!-- AOP Config --> <aop:config> <aop:aspect id="logging" ref="loggingAspect"> <aop:pointcut expression="execution(* com.example.aop.service.*.*(..))" id="service"/> <aop:before pointcut-ref="service" method="beforeAdvice"/> <aop:after pointcut-ref="service" method="afterAdvice"/> <aop:after-returning pointcut-ref="service" returning="retVal" method="afterReturningAdvice" /> <aop:after-throwing pointcut-ref="service" throwing="ex" method="AfterThrowingAdvice" /> <aop:around pointcut-ref="service" method="aroundAdvice" /> </aop:aspect> <aop:aspect id="before" ref="beforeAspect"> <aop:pointcut expression="execution(* com.example.aop.service.*.*(..))" id="service"/> <aop:before pointcut-ref="service" method="beforeAdvice"/> </aop:aspect> <aop:aspect id="afterReturning" ref="afterReturningAspect"> <aop:pointcut expression="execution(* com.example.aop.service.*.*(..))" id="service"/> <aop:after-returning pointcut-ref="service" returning="retVal" method="afterReturningAdvice" /> </aop:aspect> <aop:aspect id="afterThrowing" ref="afterThrowingAspect"> <aop:pointcut expression="execution(* com.example.aop.service.*.*(..))" id="service"/> <aop:after-throwing pointcut-ref="service" throwing="ex" method="AfterThrowingAdvice" /> </aop:aspect> <aop:aspect id="around" ref="aroundAspect"> <aop:pointcut expression="execution(* com.example.aop.service.*.*(..))" id="service"/> <aop:around pointcut-ref="service" method="aroundAdvice" /> </aop:aspect> </aop:config> </beans> ``` 5. 编写启动类 ```java import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.example.aop.service.CustomerService; public class MainApp { public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); CustomerService customerService = (CustomerService) context.getBean("customerService"); customerService.addCustomer(); System.out.println("------------------------------"); customerService.addCustomerReturnValue(); System.out.println("------------------------------"); try { customerService.addCustomerThrowException(); } catch (Exception e) { } System.out.println("------------------------------"); customerService.addCustomerAround("w3cschool.cc"); } } ``` 6. 运行结果 ``` Going to setup student profile. addCustomer() is running Student profile has been setup. ------------------------------ Going to setup student profile. addCustomerReturnValue() is running Returning:abc Student profile has been setup. ------------------------------ Going to setup student profile. addCustomerThrowException() is running There has been an exception: java.lang.Exception: Generic Error Student profile has been setup. ------------------------------ Around advice : Before method execution addCustomerAround() is running, args : w3cschool.cc Around advice : After method execution ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值