zjh 3 weeks ago
commit de159c6bfd

20
.gitignore vendored

@ -0,0 +1,20 @@
# 编译输出目录
out/
target/
build/
*.class
# IDE 配置
.idea/
*.iml
.vscode/
# 临时文件
*.log
*.tmp
*.swp
*~
# 操作系统文件
.DS_Store
Thumbs.db

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<!-- 组长的User实体 -->
<bean id="user" class="com.ssm.aop.xml.User">
<property name="id" value="1"/>
<property name="username" value="zhangsan"/>
<property name="userpass" value="123456"/>
<property name="truename" value="张三"/>
<property name="phone" value="13800130000"/>
<property name="createTime" value="2024-01-01"/>
</bean>
<!-- 于杉杉的StockAccount实体 -->
<bean id="stockAccount" class="com.ssm.aop.xml.StockAccount">
<property name="id" value="3001"/>
<property name="userId" value="1"/>
<property name="accountName" value="张三的A股账户"/>
<property name="broker" value="东方财富证券"/>
<property name="balance" value="100000.00"/>
<property name="createDate" value="2023-06-18"/>
</bean>
<!-- 籍美翎的StockAccount实体 -->
<bean id="income" class="com.ssm.aop.xml.Income">
<property name="id" value="1001"/>
<property name="userId" value="1"/>
<property name="type" value="工资"/>
<property name="money" value="5000"/>
<property name="incomeTime" value="2024-04-01"/>
</bean>
<!-- AOP日志 -->
<bean id="log" class="com.ssm.aop.xml.Log"/>
<!-- AOP配置 -->
<aop:config>
<aop:aspect ref="log">
<aop:before method="before"
pointcut="execution(* com.ssm.aop.xml..printInfo(..))"/>
</aop:aspect>
</aop:config>
</beans>

@ -0,0 +1,59 @@
package com.ssm.aop.xml;
public class Income {
private Integer id;
private Integer userId;
private String type;
private double money;
private String incomeTime;
public void printInfo(){
System.out.println("=====籍美翎-收入信息=====");
System.out.println("收入ID"+id);
System.out.println("用户ID"+userId);
System.out.println("收入类型:"+type);
System.out.println("金额:"+money);
System.out.println("时间:"+incomeTime);
}
// 必须加上 getter 和 setterSpring 才能注入值
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public double getMoney() {
return money;
}
public void setMoney(double money) {
this.money = money;
}
public String getIncomeTime() {
return incomeTime;
}
public void setIncomeTime(String incomeTime) {
this.incomeTime = incomeTime;
}
}

@ -0,0 +1,19 @@
package com.ssm.aop.xml;
import org.aspectj.lang.JoinPoint;
import java.util.Date;
public class Log {
public void before(JoinPoint jp) {
System.out.println("==================================");
System.out.println("【前置通知】开始执行方法:" + jp.getSignature().getName());
System.out.println("【前置通知】执行时间:" + new Date());
System.out.println("==================================");
}
public void before(JoinPoint jp, String param) {
System.out.println("==================================");
System.out.println("【前置通知】开始执行方法:" + jp.getSignature().getName());
System.out.println("【前置通知】执行时间:" + new Date());
System.out.println("==================================");
}
}

@ -0,0 +1,64 @@
package com.ssm.aop.xml;
import java.math.BigDecimal;
public class StockAccount {
private Integer id;
private Integer userId;
private String accountName;
private String broker;
private BigDecimal balance;
private String createDate;
// 1. 必须有无参构造
public StockAccount() {}
// 2. 作业要求printInfo方法输出所有属性
public void printInfo() {
System.out.println("\n=====于杉杉:证券账户信息=====");
System.out.println("账户ID" + id);
System.out.println("所属用户ID" + userId);
System.out.println("账户名称:" + accountName);
System.out.println("开户券商:" + broker);
System.out.println("账户余额:" + balance);
System.out.println("开户日期:" + createDate);
}
// 3. 必须提供getter/setter
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Integer getUserId() {
return userId;
}
public void setUserId(Integer userId) {
this.userId = userId;
}
public String getAccountName() {
return accountName;
}
public void setAccountName(String accountName) {
this.accountName = accountName;
}
public String getBroker() {
return broker;
}
public void setBroker(String broker) {
this.broker = broker;
}
public BigDecimal getBalance() {
return balance;
}
public void setBalance(BigDecimal balance) {
this.balance = balance;
}
public String getCreateDate() {
return createDate;
}
public void setCreateDate(String createDate) {
this.createDate = createDate;
}
}

@ -0,0 +1,16 @@
package com.ssm.aop.xml;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestAop {
public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("bean-aop.xml");
User user = (User) ac.getBean("user");
user.printInfo();
StockAccount stockAccount = (StockAccount) ac.getBean("stockAccount");
stockAccount.printInfo();
Income income = (Income)ac.getBean("income");
income.printInfo();
}
}

@ -0,0 +1,67 @@
package com.ssm.aop.xml;
public class User {
private Integer id;
private String username;
private String userpass;
private String truename;
private String phone;
private String createTime;
public void printInfo() {
System.out.println("===== 组长-用户信息 =====");
System.out.println("ID" + id);
System.out.println("用户名:" + username);
System.out.println("真实姓名:" + truename);
System.out.println("电话:" + phone);
System.out.println("注册时间:" + createTime);
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getUserpass() {
return userpass;
}
public void setUserpass(String userpass) {
this.userpass = userpass;
}
public String getTruename() {
return truename;
}
public void setTruename(String truename) {
this.truename = truename;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getCreateTime() {
return createTime;
}
public void setCreateTime(String createTime) {
this.createTime = createTime;
}
}

@ -8,7 +8,7 @@ public class TestAnnotation {
// 加载注解配置
ApplicationContext ac = new ClassPathXmlApplicationContext("bean-annotation.xml");
// 只获取组长自己的 User
User user = (User) ac.getBean("user");
user.printInfo();
StockAccount stockAccount = (StockAccount) ac.getBean("stockAccount");

Loading…
Cancel
Save