java属性监听_Java PropertyChangeListener实现对象属性监听

TorderPropertyChangeListener实现了PropertyChangeListener接口,用于监听Torder对象的属性变化。当属性值发生改变时,记录变更的属性名、旧值和新值,并通过log4j日志系统输出。
摘要由CSDN通过智能技术生成

package com.sunfairs.property;

import java.beans.PropertyChangeEvent;

import java.beans.PropertyChangeListener;

import org.apache.log4j.Logger;

public class TorderPropertyChangeListener implements PropertyChangeListener {

private static final Logger logger = Logger.getLogger(TorderPropertyChangeListener.class);

private String properties;

private String oldValues;

private String newValues;

public TorderPropertyChangeListener(){

this.properties = "";

this.oldValues = "";

this.newValues = "";

}

public void propertyChange(PropertyChangeEvent event) {

String property = event.getPropertyName();

String oldValue = String.valueOf(event.getOldValue());

String newValue = String.valueOf(event.getNewValue());

if(!oldValue.equals(newValue) && (oldValue!=null && !newValue.equals(""))){

this.properties=this.properties+","+property;

this.oldValues = this.oldValues+","+oldValue;

this.newValues = this.newValues+","+newValue;

}

logger.info("["+property+":"+oldValue+","+newValue+"]");

}

public String getNewValues() {

return newValues;

}

public String getOldValues() {

return oldValues;

}

public String getProperties() {

return properties;

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值